Ignore Test in Unit Testing using NUnit: Part 3

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.

clip_image002

You can ignore a unit test as following

clip_image004

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.

clip_image002[6]

In this post we learnt how easily a test can be ignored in NUnit. I hope you find this post useful. Thanks for reading.

One response to “Ignore Test in Unit Testing using NUnit: Part 3”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com