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

Notification

Icon
Error

ExclusivelyUsesAttribute on Test fixtures
Sane
#1 Posted : Monday, August 20, 2012 12:54:40 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/20/2012(UTC)
Posts: 3

Does NCrunch recognize ExclusivelyUsesAttribute placed on an entire test fixture?

In my project I have a separate base class for all integration tests, so I want that all test from all test fixtures that inherit integration base class are runned one by one. I try the following solution, but still get some DB-related exceptions (e.g. "The INSERT statement conflicted with the FOREIGN KEY constraint" ) from time to time.

Code:
[ExclusivelyUses("DB")]
public class IntegrationTestBase{
}

public class SomeCoolStuffTest : IntegrationTestBase{
...
}

[TestFixture]
public class ConcreteIntegrationTests{

   [Test]
   public void Test()
  {
    ...
  }

}
Remco
#2 Posted : Monday, August 20, 2012 8:53:42 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for posting!

Yes - The ExclusivelyUsesAttribute should work at fixture level, and it should also inherit through to derived tests.

There is a known problem with NCrunch where sometimes if you add a new ExclusivelyUsesAttribute onto a base class that is in a different assembly from the test itself, you'll need to reset the engine before NCrunch will properly pick it up (or just restart Visual Studio).

The best way to tell whether the attribute is working correctly is to turn on the 'Exclusively used resources' column inside the Tests Window. To do this, just right click the column headings, go to the 'Field Chooser' and drag the field onto the tree list. In theory you should see the resources being used by all the tests in each of your fixtures, but note that the fixtures themselves won't actually make use of the attribute (they implicitly inherit the attribute from their child tests, and this won't be shown in the tree list).

Thinking about the error message you're getting - make sure that the database you're testing against is properly isolated for the continuous test runner. If any other test runner is working from this database, or if you are using it for manual testing, you'll likely experience problems as described.

I noticed that in the example above, the 'ConcreteIntegrationTests' class wasn't inheriting from your base class .. but I assume this is unintentional and that your code is right.

I hope this helps!


Cheers,

Remco
Sane
#3 Posted : Tuesday, August 21, 2012 10:46:44 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/20/2012(UTC)
Posts: 3

Hi, thanks for answer.

Yes, it's a typo = ConcreteIntegrationTests inherits SomeCoolStuffTest as well.

I'll monitor 'Exclusively used resources' column value and let you know if there are anything odd with it.

Thanks,
Alex
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.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download