Create a boilerplate code for unit-testing
For a creation of a simple example solution please refer to Chapter 2b. We use same a .Net Core library project and a static method Greet(string whom):
namespace HelloWorld
{
public static class Example
{
public static string Greet(string whom)
{
return $"Hello {whom}";
}
}
}
To create a boilerplate code for this method, right-click inside the method and select “Create Boilerplate with devmate” from the context menu and choose a unit-testing framework:

A file dialog will ask you where to store the generated boilerplate code. Store it somewhere in your test project:

That’s it. You just created your first boilerplate code using devmate:
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace HelloWorldTests
{
public class GreetTestCase
{
#region Test methods
[Test]
[TestCaseSource(nameof(ExpectedReturnValueTests))]
public void GreetTest(ExpectedValueTestData<string> data)
{
var actual = HelloWorld.Example.Greet(data.Params.whom);
Assert.AreEqual(data.ExpectedValue, actual);
}
[Test]
[TestCaseSource(nameof(TestsThrowingException))]
public void GreetTestThrowingException(TestThrowingExceptionData data)
{
Assert.Throws(data.ExpectedException, () => HelloWorld.Example.Greet(data.Params.whom));
}
#endregion
#region Data
private static IEnumerable<TestCaseData> ExpectedReturnValueTests()
{
yield return new TestCaseData(
new ExpectedValueTestData<string>
{
Params = new Parameters
{
whom = /* TODO: Replace 'default' by your expected value */ default,
},
ExpectedValue = /* TODO: Replace 'default' by your expected value */ default,
}).SetName(@"set your test name here - set your test description here");
}
private static IEnumerable<TestCaseData> TestsThrowingException()
{
yield return new TestCaseData(
new TestThrowingExceptionData
{
Params = new Parameters
{
whom = /* TODO: Replace 'default' by your expected value */ default,
},
ExpectedException = /* TODO: Replace 'Exception' by your expected exception */ typeof(Exception),
}).SetName(@"set your test name here - set your test description here");
}
#endregion
#region Types
public struct ExpectedValueTestData<TExpected>
{
public Parameters Params;
public TExpected ExpectedValue;
}
public struct TestThrowingExceptionData
{
public Parameters Params;
public Type ExpectedException;
}
public struct Parameters
{
public string whom;
}
#endregion
}
}
The full source code of this example is available on Github.