C
C#3w ago
geri

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
geri
geri3w ago
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?)
[Test]
public void TestSteps()
{
// Run Step1
// Validate Step1
//Test Step2
//Validate Step2
}
[Test]
public void TestSteps()
{
// Run Step1
// Validate Step1
//Test Step2
//Validate Step2
}
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.
[Test]
public void TestStep1()
{
// Run Step1
// Validate Step1
}

[Test]
public void TestStep2()
{
// Run Step1
// Validate Step1
// Run Step2
// Validate Step2
}
[Test]
public void TestStep1()
{
// Run Step1
// Validate Step1
}

[Test]
public void TestStep2()
{
// Run Step1
// Validate Step1
// Run Step2
// Validate Step2
}
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...
[Test, Order(1)]
public void TestStep1()
{
// Run Step1
// Validate Step1
}

[Test, Order(2)]
public void TestStep2()
{
// Run Step1
// Run Step2
// Validate Step2
}
[Test, Order(1)]
public void TestStep1()
{
// Run Step1
// Validate Step1
}

[Test, Order(2)]
public void TestStep2()
{
// Run Step1
// Run Step2
// Validate Step2
}
Neither approach seems to be "good" any preferences thoughts? I hope it was understandable
Sossenbinder
Sossenbinder3w ago
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
Want results from more Discord servers?
Add your server