Unit Tests Are Not Discoverable

September 30, 2015

I recently had a situation where I loaded a solution containing a suite of NUnit tests, but the test explorer would not recognise them. The following is a series of checks to make that may cause unit tests to be not visible. Most of these are applicable to all tests:

1. Tests must be declared as public.  For example:


        public void MyTestMethod()
        {

2. Tests must be decorated with a test attribute.  

For NUnit this is is [Test]:


	        [Test]
	        public void MyNUnitTest()
	        {
	
Or [TestCase]:


	        [TestCase(1)]
	        [TestCase(2)]
	        public void MyParameterisedTest(int testNum)
	        {
	
	
For MSTest this is [TestMethod]:



	        [TestMethod]
	        public void MyTestMethod()
	        {
	
3. If using NUnit - check that the correct version is installed (remember that v3 is not an official release yet - that is, at the time of writing).

The current release test adapter is here

The test adaptor for NUnit3 is here

As usual, this is more for my own reference, but if it helps anyone else then all to the good. Also, if you think of or encounter another then please let me know in the comments and I’ll add it on.



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2022