Build/Test Issues

SpecFlow + TestContainers -- How to tweak NCrunch to behave similar to other runners?

Started by SeanKilleen on 2,447 views

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?
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.
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!

Post a reply

Log in to reply.