technical musings of a caffeine converter


MS Test missing tests

Just a quick post to highlight a bit of a ‘doh!’ moment I had earlier today that may catch out anyone else whilst in half-a-sleep mode. In adding a new service to my solution that encapsulates CRUD functionality for a new entity, I went about adding my new tests to cover all elements – unit tests and integration tests covering areas from validation, to unit of work and repositories. When running through these tests and doing the work required to make them pass, I ended up with one test failing well before I expected to be left with just the one. Digging into the other tests I came across a bunch of tests that were being missed out.

I have JustTest installed from Telerik that gives me the option of testing specific tests via the context menu so I tried this out and, sure enough, the test sprang to life in Telerik’s Unit Test console and promptly failed as it should have done. So why couldn’t MS Test see it?

The answer was simple – I had not declared by class as public. I know my tests have to be declared in a public class but it was such an easy oversight, had I not had another Unit Testing framework to compare against, I may not have spotted it as easily as I did.

Whilst the improvements to the built-in testing framework in VS 2012 Ultimate are welcome, I am surprised that the compiler could not have at least picked up that I had a class decorated with [TestClass] attribute that was not public and given me a warning. Operations that silently fail to run are dangerous to the integrity of your code – it’s like an empty catch block – the silent code killer!

So, if you are using MS Test (this may apply to other frameworks but Just Test from Telerik managed to discover the non public test class), just keep an eye out for your test class decorations.

Add comment