GreenMoose;7918 wrote:
Does this mean I should not have 2 tests within same project where the test names both are named e.g. "ItShouldThrow", no matter namespace/fixture name etc. ?
The uniqueness of a test is determined by:
- Project
- Namespace
- Fixture
- Test 'name' as reported by NUnit
In almost all circumstances, the 'name' of a test as reported by NUnit will be the method name with its parameter values. An exception to this is situations where TestCaseSourceAttribute is used, as this attribute allows the user to pass in custom type parameters that may not give unique names to individual test cases.
I would expect this problem to be very rare, but it may be common in situations where people are using a specific pattern for their tests that they repeat throughout the suite.
GreenMoose;7918 wrote:
Is this a limitation also in newer (v3) NUnit versions ?
Yes, unfortunately.
GreenMoose;7918 wrote:
Is it specific to NUnit only and can be avoided if other test frameworks are used instead?
Yes. NUnit is the only framework that has this problem, as it is the only one with internal mechanics that make it impossible to uniquely identify tests across runs other than by using the name of the test.
GreenMoose;7918 wrote:
Is this limitation expected to exist in a foreseeable future?
Unfortunately yes, unless the design of NUnit is changed. At the moment I think there is likely to be too much invested in the current 'Test Id' numbering system used by NUnit, so probably this won't be going away any time soon.
GreenMoose;7918 wrote:
Has this issue been present in all NCrunch versions except now it has been "brought to attention" with the warning?
Yes, that is correct. The problem has been with us since the first alphas of NCrunch, but many people have likely been unaware of it as one of the more common scenarios is that the tests just silently pass or are not correctly detected.
GreenMoose;7918 wrote:
What's the drawback of having duplicated test names - does it mean if 1 of them fail it can still show up as succeeded since another test with same name is passing?
This is unknown, as it depends upon the use case and the version of NUnit involved.
Where NUnit reports more than one test under the same name, NCrunch will discard any duplicates and report a single test up into the engine. When the de-duplicated test is executed by NCrunch, it will pass instructions down to NUnit to execute both duplicate tests in the run. How NUnit processes this instruction seems to be variable. I'm aware of two likely outcomes:
1. Both tests are executed. NCrunch captures the result from the last test in the run and reports this as the entire result, discarding results from any of the other duplicates. This means that if the first duplicate in the run fails, you'll have a unreported test failure.
2. None of the duplicates are executed. NCrunch will then fail the test with an error message saying that something went wrong.
Anyone with knowledge of NUnit internals would be quick to point out that NUnit does actually have a truly unique identifier that is generated and reported for each individual test(case). Unfortunately, this identifier cannot be used by NCrunch because it is generated using the sequence of tests in the suite. As the sequence of tests changes regularly (for example, you could add or remove a test from the quite), NCrunch cannot use the identifier to track tests across changes made to the test project. The result of using this would be that much of the recorded data from a test project would need to be thrown away every time a test is added or removed from the project, which just isn't acceptable.
Other frameworks (such as Gallio and Xunit) have a unique test identifier that they generate using elements of the test itself, such as its fixture, namespace, method, parameters, etc. This identifier is reliable across changes, so we don't see the problem for these frameworks. MSTest and MSpec do not have any mechanism supported by NCrunch under which more than one test can be generated from the same physical method in the assembly.
So this leaves us where we are. The only solution is to always make sure your tests are named uniquely so the engine can tell them apart. This is actually good practice anyway, as two tests that look exactly the same in the UI can be rather hard to tell apart visually.