NUnit.Extensions.Helpers.Generators
1.0.0
See the version list below for details.
dotnet add package NUnit.Extensions.Helpers.Generators --version 1.0.0
NuGet\Install-Package NUnit.Extensions.Helpers.Generators -Version 1.0.0
<PackageReference Include="NUnit.Extensions.Helpers.Generators" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add NUnit.Extensions.Helpers.Generators --version 1.0.0
#r "nuget: NUnit.Extensions.Helpers.Generators, 1.0.0"
// Install NUnit.Extensions.Helpers.Generators as a Cake Addin #addin nuget:?package=NUnit.Extensions.Helpers.Generators&version=1.0.0 // Install NUnit.Extensions.Helpers.Generators as a Cake Tool #tool nuget:?package=NUnit.Extensions.Helpers.Generators&version=1.0.0
NUnit.Extensions.Helpers
Helpers to generate NUnit tests
This is not an official NUnit package.
Install
Add the NuGet package NUnit.Extensions.Helpers to any project supporting .NET Standard 2.0 or higher.
> dotnet add package NUnit.Extensions.Helpers
Information
Currently the generated source requires Moq and FluentAssertions.
Usage
Constructor parameter null tests
Use the GenerateConstructorParameterNullTests
attribute to define the SUT (class which should be tested) to generate constructor parameter tests for.
[GenerateConstructorParameterNullTests(typeof(Document))]
internal partial class DocumentTests
{
[Test]
public void Test1()
{
Assert.Pass();
}
}
If the SUT looks like
public class Document
{
private Stream _stream;
private IFileTester _fileTester;
private IOtherFilter _filter;
public Document(Stream myStream, IFileTester fileTester, IOtherFilter filter)
{
_stream = myStream ?? throw new ArgumentNullException(nameof(myStream));
_fileTester = fileTester ?? throw new ArgumentNullException(nameof(fileTester));
_filter = filter ?? throw new ArgumentNullException(nameof(filter));
}
}
following code will be generated:
partial class DocumentTests
{
[Test]
public void Throws_Exception_When_MyStream_Is_Null()
{
Action action = () => new Document(null, null, null);
action.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("myStream");
}
[Test]
public void Throws_Exception_When_FileTester_Is_Null()
{
Action action = () => new Document(Mock.Of<System.IO.Stream>(), null, null);
action.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("fileTester");
}
[Test]
public void Throws_Exception_When_Filter_Is_Null()
{
Action action = () => new Document(Mock.Of<System.IO.Stream>(), Mock.Of<Sample.IFileTester>(), null);
action.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("filter");
}
}
Options
It's possible to generate a nested class with the AsNestedClass
argument.
[GenerateConstructorParameterNullTests(typeof(Document), AsNestedClass = true)]
internal partial class TestWithNested
{
}
Web service tests
Use the WebServiceTester
helper class. This class reads the OpenApi documentation and can execute arbitary tests.
[Test]
public async Task TestEndpointSecurity()
{
var tester = new WebServiceTester("swagger.json");
await tester.VerifySecuredEndpointsRequiresAuthentication(httpClient, CancellationToken.None);
}
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NUnit.Extensions.Helpers.Generators:
Package | Downloads |
---|---|
NUnit.Extensions.Helpers
Helpers for NUnit to generate tests more easily. |
GitHub repositories
This package is not used by any popular GitHub repositories.