This article is the third in the series about Unit Testing using NUnit. Read the first two parts of this series below:
How to do Unit Test using NUnit : Part 1
Test SetUp and TearDown in Unit Testing using NUnit : Part 2
You may come across a scenario when the test itself is broken. While executing a test you need to ignore certain broken kinds of tests. Thankfully NUnit provides a very simple solution to ignore a test. By using the ignore attribute you can ignore a test.
You can ignore a unit test as in the following:
Let us return to the unit test we wrote in the previous part of this series and modify the test as in the following:
[Test]
[Ignore("Ignore this test it is broken")]
public void IsValidProductPrice()
{
p.ProductPrice = 100;
if (p.ProductPrice > 0)
{
result = true;
}
Assert.IsTrue(result, "Product Price is valid");
}
On execution of the test you will find that Test Runner has ignored this test. Test runner will skip the test attributed with ignore.
In this article we learned how easily a test can be ignored in NUnit. I hope you find this article useful. Thanks for reading.