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.


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,

 [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.

Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

One thought on “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 )

Google+ photo

You are commenting using your Google+ 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