NUnit test class what has functions Step1,Step2,Step3...
So after each step you want to validated the mocked classes / the result of the StepN function.
StepN only has sense if StepN-1 had run correctly.
(For now I'm just talking about the ideal "good behavior" like testing for
NotThrowException
and not for TestThrowException
")2 Replies
You could do the testing in one big test case where you test the StepN's functionality .
- You'll have much assertations and checks in one testcase(which is not a great idea?)
Or you create N test cases and in every testcase you run the Steps from 0 to N-1 with validating their result.
- This results in redundant testing, and in some testcases still a lot assertations.
So you can do, NOT validating the Step results from 0 to N-1 and make sure that the TestStepN-1 test runs before TestStepN-2 by applying Order attribute to them. Then you test the StepN function...
- Testing is not redundant however calling the StepN function of the tested class is.
- Order attribute needs to be applied and some people says good tests shouldn't depend on the running order...
Neither approach seems to be "good" any preferences thoughts?
I hope it was understandable
I think you should always strive for tests containing their entire setup and teardown, never a dependency between each other. And if you are concerned that your test setup might require too much arrangement, you can always try to decouple some internals to allow it to individually test them, while only composing everything for a bigger test
In your case I kinda prefer running and validating a specific sub-step on its own, and then just take for granted that I individually tested it when I start composing a test a layer above