Home > Mobile >  Create multiple test scenarios for a method
Create multiple test scenarios for a method

Time:10-19

I'm studying unit tests in dotnet and I have a doubt about the amount of scenarios that is acceptable to be done.

Should I make just one test scenario for my method or should I create several scenarios, store them in a list and iterate them in the Act part, comparing the method's return with the expected response that is already in the list?

I don't know if it would be a good practice to create a list with possible scenarios and their respective results, if anything different from what is expected is returned, which is already stored in the list, then it would be a failure to respond.

What do you think?

CodePudding user response:

From what I can say from my experience is that you should keep it simple and you should avoid doing logic in your test.

I can really recommend the best practices provided by Microsoft.

CodePudding user response:

as far as i know, You should create unit test for successful scenario and catch the exceptions if the app throws excp.

Smhth like that:

public async Task Func_Success()
public async Task Func_NotFound()
public async Task Func_Conflict()

I think unit test should be simple and coverage lines.

  • Related