Daily Usage Issues

Ignore tests using attributes

Started by jgauffin on 7,705 views

We are using [ExclusivelyUses] for some integration tests.

But for some tests I would like that NCrunch ignores them completely. Is that possible by using attributes? Something like [SkipTest]

Each dev is using their own NCrunch settings, so I can't do it in the configuration.

Edited

Generally I'd recommend doing this by customising the engine modes in the solution with criteria that can exclude certain tests by category. You can then categorise the tests using the category attribute applicable to your test framework so that the exclusion criteria picks them up.

Engine modes are stored in the solution configuration file (.ncrunchsolution), which should usually be stored under source control and shared with all team members (see using NCrunch with source control for recommendations on which files to share with the team).

Of course, ignoring the tests via the Tests Window would also allow them to be shut off for NCrunch (again, this assumes you would share the NCrunch project configuration files using source control, which is highly recommended).

Another option is to use a compile condition so that NCrunch sees an ignore attribute adorning each of these tests when it builds them. For example, if you were using NUnit, the following would disable the test for NCrunch but not other test runners:

#if NCRUNCH
[Ignore]
#endif
[Test]
public void MyTest()
{
.. test code ..
}

Edited

This post has been deleted.
Remco wrote:Generally I'd recommend doing this by customising the engine modes in the solution with criteria that can exclude certain tests by category.


Hi Remco,

We've been doing exactly this. The only problem I've noticed is that if the ignored tests have previously failed, the "failed test count", as shown on the Risk/Progress Bar, still includes the tests that should have been ignored by the Engine Mode. I was expecting the count to show the number of failures for only those tests that are covered by the current Engine Mode.

Is this correct behaviour?
Yes, this is the intended behaviour. A test ignored by the engine mode is still considered to be a test that could be run under different circumstances (i.e. manually). It may well be that if you want the tests to be gone and never looked at by NCrunch, using the Ignored Tests feature would probably be the best option.

Sorry, I realise my post above was potentially misleading when viewed in this context.
Seems reasonable, just wanted to check!

Thanks.

Post a reply

Log in to reply.