geri
geri
CC#
Created by geri on 10/10/2024 in #help
NUnit test class what has functions Step1,Step2,Step3...
Neither approach seems to be "good" any preferences thoughts? I hope it was understandable
5 replies
CC#
Created by geri on 10/10/2024 in #help
NUnit test class what has functions Step1,Step2,Step3...
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
}
5 replies