ricaun.NUnit
1.4.0
Prefix Reserved
dotnet add package ricaun.NUnit --version 1.4.0
NuGet\Install-Package ricaun.NUnit -Version 1.4.0
<PackageReference Include="ricaun.NUnit" Version="1.4.0" />
paket add ricaun.NUnit --version 1.4.0
#r "nuget: ricaun.NUnit, 1.4.0"
// Install ricaun.NUnit as a Cake Addin #addin nuget:?package=ricaun.NUnit&version=1.4.0 // Install ricaun.NUnit as a Cake Tool #tool nuget:?package=ricaun.NUnit&version=1.4.0
ricaun.NUnit
ricaun.NUnit is a package to manage the Load and Test assemblies using the NUnit Attributes as patterns.
Features
var location = Assembly.GetExecutingAssembly().Location;
var test = TestEngine.TestAssembly(location);
Test Attributes
The tests use the NUnit Attributes [Test]
to execute a method test.
- The attribute
[SetUp]
and[TearDown]
is executed for each method with the attribute[Test]
. - The attribute
[OneTimeSetUp]
and[OneTimeTearDown]
is executed one time before each method with the attribute[Test]
. - The attribute
[Ignore]
makes the class or method to be ignored. - The attribute
[Order]
makes the order that the test will run in. - The attribute
[Explicit]
works only if theFilter
is enable. - The attribute
[TestCase]
disable theOptional Parameters
- The attribute
[TestCaseSource]
disable theOptional Parameters
public class TestSampleClass
{
[OneTimeSetUp]
public void OneBeforeTest()
{
Console.WriteLine("Execute OneBeforeTest");
}
[OneTimeTearDown]
public void OneAfterTest()
{
Console.WriteLine("Execute OneAfterTest");
}
[SetUp]
public void BeforeTest()
{
Console.WriteLine("Execute BeforeTest");
}
[TearDown]
public void AfterTest()
{
Console.WriteLine("Execute AfterTest");
}
[Test]
public void NormalTest()
{
Console.WriteLine("Execute NormalTest");
Assert.True(true);
}
[Test]
public void FailTest()
{
Console.WriteLine("Execute FailTest");
Assert.True(false, "This is a custom fail message.");
}
[Test]
public void PassTest()
{
Console.WriteLine("Execute PassTest");
Assert.Pass("This is a custom pass message.");
}
[Test(ExpectedResult = 1)]
public int ResultTest()
{
return 1;
}
[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
public void CasesTest(int i)
{
Assert.True(i > 0);
}
public static int[] CasesSource = new[] { 1, 2, 3 };
[TestCaseSource(nameof(CasesSource))]
public void CasesSourceTest(int i)
{
Assert.True(i > 0);
}
}
TestFullNames
Is possible to get all the test names in the Assembly
.
var location = Assembly.GetExecutingAssembly().Location;
string[] tests = TestEngine.GetTestFullNames(location);
To force the Assembly
to load references in another folder using directoryResolver
as a directory.
var location = Assembly.GetExecutingAssembly().Location;
string[] tests = TestEngine.GetTestFullNames(location, directoryResolver);
The name of the test equal to: Namespace
.Type
.Method
.TestNameAlias
.
TestFullName
Is possible to get test FullName using TestModel
.
TestModel test;
string testFullName = test.FullName;
The name of the test equal to: TypeName
.TestName
.TestAlias
.
Filter
Is possible to add a custom filter to test only a specific test name, the filter uses WildcardPattern
.
TestEngineFilter.Add("*"); // Select all tests
TestEngineFilter.Add("*.Test"); // Test endswith
TestEngineFilter.Add("*.Test1"); // Test endswith
TestEngineFilter.Add("*.Test2"); // Test endswith
TestEngineFilter.Add("namespace.type.method.Test1"); // Test specific name
TestEngineFilter.Add("namespace.type.method.Test2"); // Test specific name
If filter is enable the [Explicit]
tests is not skipped.
TestEngineFilter.Reset(); // Reset filter
Result
Result
allow receiving a test result when the TestEngine
is running.
Use TestEngine.Result
to apply an interface ITestModelResult
.
TestEngine.Result = new TestModelResult((testModel) =>
{
Debug.WriteLine(testModel);
});
var location = Assembly.GetExecutingAssembly().Location;
var test = TestEngine.TestAssembly(location);
TestEngine.Result = null;
Fail
Fail
allow to create a test with a custom Exception
for each testNames
.
var exception = new Exception();
var test = TestEngine.Fail(location, exception);
var testNames = new string[] { "Test1", "Test2" };
var test = TestEngine.Fail(location, exception, testNames);
Optional Parameters
Is possible to add optional parameters in the class or method tested.
The custom arguments is selected based in the Type
of the argument, if the Type
is not found the test gonna execute with null
argument.
var location = Assembly.GetExecutingAssembly().Location;
var test = TestEngine.TestAssembly(location, "This is a custom string parameter.");
The sample below show some implementation with a method with argument and Constructor/IDisposable
.
public class TestParameterClass : IDisposable
{
public TestParameterClass(string parameter)
{
Console.WriteLine($"Constructor TestParameterClass: {parameter}");
}
[Test]
public void ParameterTest(string parameter)
{
Console.WriteLine($"ParameterTest: {parameter}");
Assert.IsNotNull(parameter);
}
public void Dispose()
{
Console.WriteLine($"Dispose TestParameterClass");
}
}
Release
License
This project is licensed under the MIT License.
Do you like this project? Please star this project on GitHub!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ricaun.NUnit:
Package | Downloads |
---|---|
ricaun.RevitTest.Command
Contract to create a Console application for package ricaun.RevitTest.TestAdapter. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.4.0 | 878 | 9/19/2024 |