Can anybody point me to some resources for Give-When-Then style of testing with NUnit?
To mark a method as a test case, we need to add a Test attribute. It tells the NUnit framework that it should run this method. It's a good approach to run our test methods with different arguments, without copy-pasting our test methods. We can define test method parameters by using the [TestCase] attribute.
NUnit provides a console runner (nunit3-console.exe), which is used for batch execution of tests. The console runner works through the NUnit Test Engine, which provides it with the ability to load, explore and execute tests.
So for using Nunit we need to go for Nuget Package Manager and download it. Now after installing the Nunit we need one more dll that needs to be installed in the project. The NUnit Test Adapter allows you to run NUnit tests inside Visual Studio.
The Given When Then style correlates closely to the Arrange Act Assert style for unit testing.
Here's an example:
[Test]
public void RotateAngle_Given27Degress_Returns64Degrees()
{
//Arrange or Given
var someAngleClass = new Angle();
//Act or When
var result = someAngleClass.Rotate(27);
//Assert or Then
Assert.That(result, Is.EqualTo(64));
}
The great thing about this testing style is you don't need to see the underlying code to understand the intent of the behavior.
For more info here are some sites:
http://www.arrangeactassert.com/
Roy Osherove's Blog
http://www.artofunittesting.com/
I know this is an old question, but if you haven't already, you should check out SpecFlow. It allows you to write the spec in clear text in a feature file. The tool will auto-generate NUnit tests based on the feature file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With