We have been learning Unit Testing using NUnit together. Read first two part 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 test is itself broken. While executing test you need to ignore certain broken kind of test. Thankfully NUnit provides a very simple solution to ignore a test. By using ignore attribute you can ignore a test.
You can ignore a unit test as following
Let us go back to unit test we wrote in previous part of this series and modify test as 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 test you will find that Test Runner has ignored this test. Test runner will skip test attributed with ignore.
In this post we learnt how easily a test can be ignored in NUnit. I hope you find this post useful. Thanks for reading.
Leave a Reply