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

Notification

Icon
Error

NCrunch Runs Wrong Test(s)
CoolBreeze
#1 Posted : Wednesday, February 22, 2017 2:12:49 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
I'm testing a web application using NCrunch and Selenium.

The web app has several forms for collecting name, DOB (Date of Birth), address, including State, Zip, etc.

Up to this point NCrunch has worked fantastic running the tests.

This morning I noticed two problems:

1) NCrunch ran State tests when I had selected Zip tests.
2) NCrunch ran a test for DOB "01/01/9999" when I had selected DOB test "01/A/2016".

Visual Studio 2010
NCrunch: 3.3.06

NuGet packages.config:
<package id="NUnit" version="3.6.0" targetFramework="net40" />
<package id="Selenium.Support" version="3.0.1" targetFramework="net40" />
<package id="Selenium.WebDriver" version="3.0.1" targetFramework="net40" />
<package id="Selenium.WebDriver.IEDriver" version="2.53.1.1" targetFramework="net40" />

I recently switched from IEDriver 64-bit version to 32-bit version (64-bit version is slow. 32-bit version is faster).

Web app\Test structure. I'm mentioning this structure b\c it's more complicated than a simple set of tests and I'm wondering whether sub-classing the tests might have some connection to the problems I noted above.

The main data entry page has four sub-forms. Here's the forms with a few of the input elements:

Form A: DOB, States, Zip
Form B: States, Zip
Form C: States, Zip
Form D: States, Zip

I created a test with test case factory in Form A test class. For example for Zip I have a test method and a test factory.

For Form B tests I created a subclass of the Form A Zip test and pointed the test to reference the Form B zip field.

In total there are about 1,300 tests.


I've disabled\enabled NCrunch.
I've shutdown VS and then restarted it.

The disable\enable of NCrunch might have solved problem 1.

I'll continue to diagnose the problem and will report any additional information I discover.


Update 1:

When I run a specific DOB test I noticed DOB test case factory is called:

Form A: 11 times
Form D: 2 times (this form also collects DOB).

Then test method is called.

Again, I wanted to test DOB "01/A/2016". NCrunch actually ran DOB "//" test.

Just curious: Is it normal behavior for NCrunch to call the test factory more than once?

I assume NCrunch would call the test factory once for Form A DOB test and then once Form D DOB test.

Also, when I ask NCrunch to run a specific test from a test factory does NCrunch match on test description to find that specific test?


Update 2:

In the past:

I created test method to run each test case one at a time. This allows me to run a specific test, for example, DOB "01/A/2016" from the NCrunch tests window and see the results for that one test.

I created a second test method to run all DOB tests for a specific form which I might call something like DOBMany. This, obviously, allows me to run all test for one field with a quick selection and click.

Today:

If I select and run DOBMany NCrunch calls the test method for running a single test instead of calling the test method for running all DOB tests.


Update 3:

I rebooted my box and restarted the two VS projects and then ran some tests. Same problem. NCrunch runs wrong test.


Thanks, Ed
Remco
#2 Posted : Wednesday, February 22, 2017 8:35:00 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Ed,

Can you share any details about how these tests are being generated? Are you using TestCaseSource?

The working of this are all behind the test framework itself (NUnit3), though I think this may be a test case identification issue of some kind. If the tests don't have unique and distinctive names that NCrunch can use to separate them, it's possible to have erratic behaviour like this.

Has NCrunch given you any warnings about tests existing under the same name?
CoolBreeze
#3 Posted : Thursday, February 23, 2017 2:44:37 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Hi Remco,

You are correct. There were multiple tests with the same name. I cleaned up the duplicate names and selected and ran a test from the Tests window and NCrunch ran the correct test.

re: Can you share any details about how these tests are being generated? Are you using TestCaseSource?

I use both TestCase and TestCaseSource.

re: Has NCrunch given you any warnings about tests existing under the same name?

Yes, NCrunch gave me warnings. However, I didn't see them due to the large number of tests.

Just wondering if there's any way to notify the developer about the duplicate names in a more direct manner. Perhaps an alert popup?

I thought I could add a check for duplicates in my test factories and then throw an exception. But it appears NCrunch swallows the exception so I don't see the exception.

Thanks for your help,

Ed
CoolBreeze
#4 Posted : Thursday, February 23, 2017 6:16:58 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
I may have spoken too soon.

I select and run a zip code test but NCrunch calls the Phone or States test method.

I don't see any warnings for duplicate test descriptions. I think I fixed all of those problems.

Any other ideas?

Thanks, Ed
CoolBreeze
#5 Posted : Thursday, February 23, 2017 8:12:06 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
I'm working on the theory that the mix-up is due to the same argument signature for some tests.

For example:

I have a base TEST_DATA_TestCase class.

I create several zip code and phone number tests using that class.

The test methods might look like:

Public Sub Phone(TestObj As TEST_DATA_TestCase)
Public Sub Zip(TestObj As TEST_DATA_TestCase)

I sub-classed TEST_DATA_TestCase and created two new classes:

TEST_DATA_Phone
TEST_DATA_Zip

Then updated my test method argument signatures:

Public Sub Phone(TestObj As TEST_DATA_Phone)
Public Sub Zip(TestObj As TEST_DATA_Zip)

When I run my Zip code test it is now running the Zip test method.

I'm checking the other test methods for the base TEST_DATA_TestCase and will be creating a sub-class specific to the test.

Thanks, Ed
Remco
#6 Posted : Thursday, February 23, 2017 10:56:44 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Ed,

When using user types as parameters to test cases, you need to be very careful to make sure that the name NUnit is generating for the test is unique. If you have two tests with different instances of the same user type, it's possible that NUnit's generated name for the tests ends up being identical.

When generating tests using TestCaseSource, it's also important that the sequence of the generation is consistent. This is because NUnit creates an incremental identifier that is later used by NCrunch to identify each generated test. Consistency and distinction are extremely important when generating tests dynamically.
CoolBreeze
#7 Posted : Friday, February 24, 2017 3:35:52 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Hi Remco,

I may have made some improvement in my situation, but I'm not 100% sure. The situation is still a little confusing.

re: make sure that the name NUnit is generating for the test is unique

I override ToString() on my test case data classes and format a test description based on some test data values. So I thought I was generating a unique name for all test cases.

Initially, that's what I thought you meant. Is the description generated by ToString() and displayed in the NCrunch Tests window different than the NUnit generated name?

I'm guessing that's the case.

I see in the NUNit documentation these TestCase methods:

.SetDescription()
.SetName()

I guess that means my ToString() is providing the string for SetDescription.

Therefore, NUnit is generating it's own name.

Another thing I tried was to set the test description like this:

<Test("DivideByZero")> _

Then I selected and ran a group of DOB tests and then checked my test logs. I display the test case value in the logs. I see the test case value in the logs matches the test case value in the test description.

So it appears adding the test description solved the problem. However, I'll need to do more testing to feel confident that's true.

The other option is to call SetName(). Depending on whether I have time today or next week I'll try that option. I have to run these tests and deploy a version of this app to our test server. So I need to focus on that at the moment.

Thanks, Ed




Remco
#8 Posted : Friday, February 24, 2017 9:45:48 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Ed,

I wish I could give a fast answer on this, but it would take either some running through the NUnit source code or a bit of testing to confirm whether the description would be enough. Personally, I would recommend SetName, because this is one that I'm sure will work. In all prior situations when people have had problems with inconsistent test naming, I've always recommend .SetName as the solution to this.

CoolBreeze
#9 Posted : Friday, February 24, 2017 9:56:49 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Hi Remco,

I've been studying the SetName more deeply this afternoon by looking at some examples and I agree with you SetName appears to be the way to go.

I have a test to test invalid\valid characters in a field. I created the test to login to the app once, fill in default values, and then only change the field under test, try to save the form, and then check for success or error alert. I selected checking Last Name field and NCrunch ran through last name, first name, city, street address, etc (all text fields).

Monday I'll try the SetName() method. I'll let you know what happens.

Thanks, Ed
1 user thanked CoolBreeze for this useful post.
Remco on 2/25/2017(UTC)
CoolBreeze
#10 Posted : Thursday, March 16, 2017 5:08:52 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Hi Remco,

I used TestCaseData.SetName as you suggested.

Initially, this appeared to clear up the problems. I selected a specific test and NCrunch ran the test I selected. So things were good for awhile.

But I started to encounter the same problem and other odd problems:

1) Selecting Wrong Test

I still see the same problem as I originally reported.

Suppose I have two tests:

CarCount
DOB

I use SetName in test factory for both tests.

I would select and run DOB test several times and then on the next test run NCrunch would run CarCount.

I updated the DOB test SetName to include the test class name:

Initial name: DOB
Updated name: Applicant Information - DOB

Then NCrunch would run the test I selected.

Note:

NCrunch is displaying "NUnit tests have been detected with the same name."

The tests listed under that warning have a completely different name than the tests I listed above.

For example: test name = StringMin

I didn't think to clear up those the name problems since the names are different than the two examples I show above. Plus, I'm not running those tests with the same name at this time.


2) NCrunch runs test and reports success with green check mark.

I select a test, say DOB, then right-click, select "Debug selected test..."

NCrunch appears to start to run the test in debug-mode then processing stops and NCrunch displays green check mark.

I'm using Selenium to test a web application. The test doesn't even run far enough to open the browser window.

3) NCrunch displays some error about test arguments not matching

I select a test, say DOB, then right-click to run test in debug-mode then processing stops and NCrunch displays error in bottom half of Tests split screen
with an error indicating test arguments are not correct (sorry don't have copy of error message. When I see error again I'll add it to this post).

This happens when I just ran the same test say 5 times.

I just updated to NCrunch 3.6.

Visual Studio 2010 (yes - I know we're behind in VS version. There's nothing I can do about it)

I think the test project I'm working on is the most complicated I've designed since starting to use Nunit and NCrunch.

The first set of test projects I created usually contained a 1-2 dozen test classes, one of the larger test project has a few hundred test classes (but the classes not not subclassed).

The test project I'm working on now has dozens of test classes but a lot of the classes are subclassed.

Will post more information as I discover it.

Thanks, Ed

CoolBreeze
#11 Posted : Thursday, March 16, 2017 9:11:22 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Additional note:

Sometimes I get:

"NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error - was the execution process terminated?"

I successfully ran the test several times prior to seeing above message.

I disabled NCrunch, closed Tests window, reopened Tests window, enabled NCrunch.

I ran another test to completion.

But I still see above message sometimes.



If I change SetName value (example):

From: Search 1
To: Search 2

Then NCrunch runs the correct test several times.

But then I have to keep changing test name occasionally in order to continue running tests.



Remco
#12 Posted : Thursday, March 16, 2017 11:04:42 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Ed,

Internally, NUnit uses sequentially generated IDs to represent the tests it discovers.

NCrunch can't use these IDs between different versions of your assembly/project, because it's natural that the list of tests in the project could be changed while you work. You add them, remove them, etc. This would cause the IDs to shift between tests making it impossible to identify them between verions of the project. For this reason, NCrunch generates its own identifier using data related to the test, such as its fixture, method, parameters, and the results of the .SetName() method.

If you're no longer seeing a report about duplicate test names for the tests involved, then .SetName() is working correctly and NCrunch is not having difficulty telling the tests apart.

However, because NUnit can only be instructed to run tests using its own internal ID, NCrunch still uses these IDs within the scope of a single codebase version to instruct NUnit on which tests to execute. Although the IDs are dumped between versions of a project (where they no longer apply), they are re-used between processes that are created for parallel execution. NCrunch assumes that invoking an NUnit test discovery action over the same test assembly will always return the same result with the same set of sequential IDs, with the same tests returned to NUnit in the same order.

There are theoretical situations where this won't hold true. For example, if you are generating your tests out of a database, the state of the database might change without NCrunch being aware of it. Because the test project/assembly hasn't changed, NCrunch assumes everything is fine even though the state used to generate the tests may have changed. This causes inconsistencies in test identification, because the physical list of tests to execute has shifted out from under the engine.

The problems you're describing match a scenario like this. Note that because the IDs are sequential, these inconsistencies can affect the entire test assembly when they appear. You may have just one test declared early in the test suite that 'disappears' after it is discovered, and then every other test in the suite will have execution problems and may report inconsistent results.
CoolBreeze
#13 Posted : Monday, March 20, 2017 12:40:19 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/11/2014(UTC)
Posts: 79
Location: United States of America

Was thanked: 9 time(s) in 9 post(s)
Hi Remco,

Thank you for the detailed explanation. I think that information on the internal working of NCrunch & NUnit helps me a lot to understand the problems I'm encountering.

When I run into problems what's the best way to fix the problem?

Disable and then re-enable NCrunch?

Shutdown and restart Visual Studio?

Reboot computer?

Or, maybe simply change the SetName of one of my tests.



Ed
Remco
#14 Posted : Monday, March 20, 2017 12:45:37 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Ed,

If possible, I would suggest evaluating your tests to try and find anything that might give an inconsistent sequence or result.

It might be possible to reproduce the behaviour by repeatedly running the same tests using the NCrunch Tests Window. If you can do this, I'd recommend turning on your logging with a log verbosity of 'Detailed'. Inside the log you'll find a raw bunch of XML that is output by NUnit during test discovery. Comparing this XML with other discovery runs on the same version of the assembly may yield some interesting differences.

A full reset of NCrunch will usually solve all problems, but as I'm not sure how your tests are generated or whether there is another dependency, it's hard for me to be certain of this. Restarting VS will likely do nothing.
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.100 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download