Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Doesn't recognize multiple tests with same name using [ValueSource] (NUnit)
tjahn
#1 Posted : Friday, April 1, 2016 7:52:23 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/24/2015(UTC)
Posts: 9
Location: Germany

Thanks: 1 times
Was thanked: 3 time(s) in 3 post(s)
Hi Remco,

occasionally I would like to pass objects (of a 3rdparty type I cannot modify) to an NUnit test. These objects unfortunately do not provide a proper ToString() implementation (with unique values).

Example (using object for the sake of simplicity):

Code:
    internal sealed class Fixture
    {
        private static readonly object[] Values = { new object(), new object() };

        [Test]
        public void Test([ValueSource("Values")] object value) { }
    }


In this case NCrunch only detects a single test instead of the two tests that gets executed when running using the NCrunch runner.

I am aware of the fact that in this situation both tests cannot be distinguished in the test overview. On the other hand I would prefer to see all tests that NUnit would run with one of the NUnit test runners. ;-)

What do you think?

Kind regards,
Tobias
Remco
#2 Posted : Friday, April 1, 2016 10:35:54 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Tobias,

Unfortunately there is a much deeper issue here with tests like this one. At some root level of a test framework, it must be possible to uniquely identify a test within a discovery or execution run. This is because data is collected from the test that needs to be organised across multiple test runs, and NCrunch also needs to be able to specifically tell the test framework which tests to execute in a given batch.

When the only element of a test case that can distinguish it from any other test case happens to be user type parameter that does not override .ToString(), there is no physical way to tell the test apart - not just in the UI of any runner, but also down in the runner and the test framework.

It's easy to see how this is less important when using a test runner that only runs all the tests end-to-end. In this context, there is no need to correlate data across test runs, or even selectively identify which tests are to be executed - you just run them all. This is why your tests are still able to run with many of the standard tools. Internally, NUnit uses sequentially generated IDs for every test inside an assembly. This allows it to uniquely identify tests, but only within the scope of a single session - if the assembly is changed, the identifiers are invalidated and all data must be thrown away.

Xunit actually has a similar problem and it introduces a level of handling to prevent these tests from causing problems. When it detects test cases that rely on a user defined type, it will immediately 'roll them up' into a single physical test representing all test cases. This allows both the framework and the runner to function without unexpected issues, but it does in some ways defeat the point of creating granular test cases with individual pass/fail results.

So basically what we're dealing with here is a technical constraint with no ideal workaround. All I can advise is that you design your tests accordingly.
2 users thanked Remco for this useful post.
tjahn on 4/4/2016(UTC), noahaltsrc on 5/25/2016(UTC)
tjahn
#3 Posted : Monday, April 4, 2016 5:02:59 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/24/2015(UTC)
Posts: 9
Location: Germany

Thanks: 1 times
Was thanked: 3 time(s) in 3 post(s)
Hi Remco,

thank you for your explanations! Now I understand the limitations and consequences when having scenarios like the one above.

Kind regards,
Tobias
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.032 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download