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

Notification

Icon
Error

SpecFlow + TestContainers -- How to tweak NCrunch to behave similar to other runners?
SeanKilleen
#1 Posted : Wednesday, July 20, 2022 1:00:03 PM(UTC)
Rank: Newbie

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

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

I love NCrunch as a product but I'm a bit inexperienced with how to tweak it for certain situations.

In my current case, I have a SpecFlow project using SpecFlow.xUnit (so, generating xUnit tests). I'm using Testcontainers with this project.

My tests are structured in the below way:

  • SpecFlow's BeforeTestRun fires, which happens once per test run
  • The BeforeTestRun method uses TestContainers to create a Neo4j container
  • The tests execute using the database that has been spun up
  • The tests end and the container is cleaned up automatically

This works as expected when using the VS and ReSharper test runners. However, with NCrunch, it appears to execute the BeforeTestRun method multiple times, which results in failures due to trying to recreate the container.

I attempted disabling parallel testing in NCrunch but that didn't appear to resolve the issue.

Is there a setting I can tweak so that the BeforeTestRun called by SpecFlow will not be called multiple times?
Remco
#2 Posted : Wednesday, July 20, 2022 11:42:32 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,614

Thanks: 869 times
Was thanked: 1183 time(s) in 1103 post(s)
Hi, thanks for posting!

This behaviour is due to a technical difference with how NCrunch is implemented vs serial test runners. There are usually ways you can solve this in your own code - see test atomicity for more information.
SeanKilleen
#3 Posted : Wednesday, July 20, 2022 11:50:30 PM(UTC)
Rank: Newbie

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

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Those tips in test atomicity are exactly what I needed. Don't know how I missed them before! I see the point and feel very confident they'll solve the problem. Thanks!
1 user thanked SeanKilleen for this useful post.
Remco on 7/20/2022(UTC)
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.025 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download