'NUnit Test Per Database Row?
I don't know if this is possible, but I'll go ahead and explain what I'm trying to do.
I want to create a test fixture that runs a test with 5 different types of inputs that come from a database.
TestFixture
Test using input1
Test using input2
Test using input3
Test using input4
Test using input5
This way, I can see from the NUnit GUI exactly which input is causing the failure, but I don't know how to do this. Currently, I have something set up like this:
[TestFixture]
public class Tester{
[Test]
public void RunTest(){
var inputs = db.inputs.where(a=>a.id < 6).ToList();
bool testSuccess=true;
foreach(var input in inputs){
bool success = RunTheTest(input);
if(success==false){
testSuccess=false;
}
}
//Tell NUnit that the entire test failed because one input failed
}
}
In this case, in NUnit, I see:
Tester
RunTest
And even though RunTest tries 5 different inputs, I only know if there was one or more inputs that failed, but I have no idea of which input failed. Basically what I'm asking is if it's possible to dynamically create tests that show up in the NUnit GUI based on whatever I want to grab from the database.
Solution 1:[1]
Look at the TestCaseSource attribute. This will let you define another method that, at runtime, will create test cases for each item returned from the source method.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pedro |
