There is a good comparison of the 3 unit test libraries:
https://xunit.net/docs/comparisons
Showing posts with label nunit. Show all posts
Showing posts with label nunit. Show all posts
July 12, 2022
February 16, 2021
Using Test Files in a Unit Test with NUnit
Insert the files into the project under a new directory say “TestData”. Include them in the project and change the build action on each file such that the “Copy to Output Directory” option should be “Copy if newer”.
Somewhere in your test:
Somewhere in your test:
// Create a path to the TestData directory using the // NUnit “TestContext.CurrentContext.TestDirectory” property private string TestFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData");…
// Now you have access to the files string testFilePath = Path.Combine(TestFilePath, @"TestFile1.mib");
March 2, 2017
NUnit Parameterised Tests
NUnit can have class level parameterised tests:
[ TestFixture( MachineEnum.None ) ]
[ TestFixture( MachineEnum.Lathe ) ]
[ TestFixture( MachineEnum.Miller ) ]
public class SomeTests
{
private readonly MachineEnum _machineEnum = MachineEnum.None;
public SomeTests(
MachineEnum machineEnum )
{
_machineEnum = machineEnum;
}
...
}
Also the tests can be paramterised at the test level. Make sure the TestCase parameter match the order and type of the test method.
[Test]
[TestCase("some value", null, ExpectedResultEnum.Paramater1Used)]
[TestCase("some value", "over ride", ExpectedResultEnum.Paramater2Used)]
[TestCase("some value", "over ride", ExpectedResultEnum.Paramater1Used)]
[TestCase(null, null, ExpectedResultEnum.Paramater1Used)]
public async Task ParamterisedTest(
string param1,
string param2,
ExpectedResultEnum expectedResult)
{
// Arrange
// Act
// Assert
Assert.Multiple(() =>
{
Assert.That(var1 == null, Is.False);
Assert.That(var2.Id, Is.EqualTo(expectedResult));
});
...
}
Subscribe to:
Posts (Atom)