Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:16:09+00:00 2026-06-12T08:16:09+00:00

I’m running ncrunch, in a new MVC 4 solution in VS2012 using nunit and

  • 0

I’m running ncrunch, in a new MVC 4 solution in VS2012 using nunit and ninject.

When I first open the solution all 50 or so test run and pass successfully.

After I make any code change (even just a added empty space) ncrunch reports that most of my unit test fail. The same thing happens if I press the ‘run all tests’ in the ncrunch window.

But if you hit the ‘Run all tests visible here’ button all 50 test pass again and ncrunch reports everything is fine.

Also when you run each test individually they pass every time.

When they do fail they seem to be failing in my ninject setup code

Error: TestFixtureSetUp failed in ControllerTestSetup

public class ControllerTestSetup
{

    [SetUp]
    public void InitIntegrationTest()
    {
        var context = IntegrationTestContext.Instance;
        context.Init();
        context.NinjectKernel.Load<MediGapWebTestModule>();
    }

    [TearDown]
    public void DisposeIntegrationTest()
    {
        IntegrationTestContext.Instance.Dispose();
    }
}

public class IntegrationTestContext : IDisposable
{  

    private static IntegrationTestContext _instance = null;
    private static readonly object _monitor = new object();

    private IntegrationTestContext() { }

    public static IntegrationTestContext Instance
    {
        get
        {
            if (_instance == null)
            {
                lock (_monitor)
                {
                    if (_instance == null)
                    {
                        _instance = new IntegrationTestContext();
                    }
                }
            }

            return _instance;
        }
    }
}

All the test also run in the resharper test runner without problems every time.

Does anyone know what could be causing this?

I guessing its something to do with the singleton lock code inside the Instance property but I’m not sure.

==============================================================================
Progress:

I was able to track this down to a error in the ninject setup method above by wrapping it in a try catch statement, and writing the error to the output window.

The exception was caused by trying to load a module more than once, even tho I definitely haven’t and I don’t use any type of automatic module loading.

This happen on the lines

LocalSessionFactoryModule.SetMappingAssemblies(() => new[] { typeof(ProviderMap).Assembly });

_kernel.Load<LocalSessionFactoryModule>();
_sessionFactory = _kernel.Get<ISessionFactory>();

where LocalSessionFactoryModule is the ninject module class derived for NinjectModule class.

Why is this only happening with ncrunch and what can I do to solve this issue? Is there a way to check if a module has already been loaded?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:16:11+00:00Added an answer on June 12, 2026 at 8:16 am

    NCrunch will never execute tests concurrency within the same process, so unless you have multi-threaded behaviour inside your test logic, then it should be safe to say that this isn’t an issue caused by the locking or threading over the singleton.

    As you’ve already tried disabling parallel execution and this hasn’t made a difference, I’m assuming that the problem wouldn’t be caused by concurrent use of resources outside the test runner process (i.e. files on disk).

    This means that the problem is almost certainly related to the sequence in which the tests are being executed. Almost all manual test runners (including Resharper) will run tests in a defined sequence from start to finish. This is good for consistency, but it can mask problems that may surface when the tests are run in an inconsistent/random order. NCrunch will execute tests in order of priority and can also reuse test processes between test runs, which can make the runtime behaviour of your tests different if they haven’t been designed with this in mind.

    A useful way to surface (and thus debug) sequence related issues is to try running your tests in a manually defined order by using NCrunch. If you right-click a test inside the NCrunch Tests Window, under the ‘Advanced’ menu you’ll find an option to run a test using an existing task runner process. Try this action against several of your tests to see if you can reproduce the sequence that surfaces the problem. When it happens, you should easily be able to get a debugger onto the test and find out why it is failing.

    Most sequence related problems are caused by uncleared static members, so make sure each of your tests is written in the assumption that existing state may be left behind by another test that has been run within the process. Another option is to ensure all state is fully cleared by tests on tear down (although in my opinion, this is often a less pragmatic approach).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.