9

I recently starting using NUnit to do integration testing for my project. It's a great tool, but I've found one drawback that I cannot seem to get the answer to. All my integration tests use the TestCaseSource attribute and specify a test case source name for each test. Now the problem is that preparing these test case sources takes quite some time (~1 min.) and if I'm running a single test, NUnit always loads EVERY SINGLE test case source, even if it's not a test case source for the test that I'm running.

Can this behavior be changed so that only the test case source(s) for the test I'm running load? I want to avoid creating new assemblies every time I want to create a new test (seems rather superfluous and cumbersome, not to mention, hard to maintain), since I've read that tests in different assemblies are loaded separately, but I don't know about the test case sources. It's worth mentioning that I'm using Resharper as the test runner.

TL;DR: Need to tell NUnit to only load the TestCaseSources that are needed for the tests running in the current session. Current behavior is that ALL TestCaseSources are loaded for any test that is run.

Anshul
  • 1,302
  • 3
  • 15
  • 36
  • Can you provide some code which demonstrates the current behavior? – Alexander Stepaniuk Sep 08 '13 at 09:34
  • Sure, I'll edit the original question shortly and add the code that I'm using. – Anshul Sep 10 '13 at 18:06
  • This demonstrates the behaviour for me - running ReSharper 6 on VS2013. Apologies for the formatting - I didn't want to post it as a not-an-answer answer. Even if I'm not running `TestWhichIAmNotRunning`, ReSharper will evaluate `InfiniteValues`, which will return `1` (almost) forever. - - - - - `public static IEnumerable InfiniteValues { get { while ( DateTime.Now != DateTime.MinValue ) yield return 1; } } [Test, TestCaseSource("InfiniteValues")] public void TestWhichIAmNotRunning(int value) { }` – Wai Ha Lee Mar 16 '15 at 17:54
  • I've contacted JetBrains and linked to this question - should they get back to me I'll post something here. – Wai Ha Lee Mar 16 '15 at 17:57
  • possible duplicate of [Delay-loading TestCaseSource in NUnit](http://stackoverflow.com/questions/5828125/delay-loading-testcasesource-in-nunit) – Wai Ha Lee Mar 26 '15 at 17:29
  • My feedback from JetBrains was basically that the behaviour in Resharper is intended, since Resharper just uses NUnit behind the scenes. – Wai Ha Lee Mar 26 '15 at 17:50

1 Answers1

1

Could you do this by moving your sources instantiation to a helper method and call them in the setup methods for each set of tests? I often have a set of helper methods in my integration test suite that set up shared data for different tests. I call just the helper methods that I need for the current suite in the [Setup]

Jim Sowers
  • 368
  • 3
  • 7
  • You could do that, but then how would you use TestCaseSource attribute to assign the test case sources to methods? I was aiming to use the TestCaseSource attribute because it takes care of object array to parameter array translation and makes testing more modular. – Anshul Sep 06 '13 at 17:23
  • Seems like a good idea, but it doesn't won't work with the TestCase source attribute. I also tried moving this to the constructor of the test class but it seems like the TestCaseSource is evaluated very early. This is a real pain for integration tests that use TestCaseSources that map from the database. – David Hoffman Apr 28 '17 at 13:48