Question

Related to a previous question that can be found here:

tests failing when "Run All Test in Solution" is used

The Test Method:

[TestMethod]
public void AMAC_Route_Maps_to_AMACController()
{
    "~/amac/".ShouldMapTo<AMACController>(action => action.Index());

}

The Route:

routes.MapRoute(
            name: "AMAC",
            url: "amac/",
            defaults: new { controller = "AMAC", action = "Index" }
        );

The Error Returned:

Test method MBS.Exec.Enquiry.MVC.Tests.AMACControllerTest.AMAC_Route_Maps_to_AMACController threw exception: MvcContrib.TestHelper.AssertionException: The URL did not match any route

This error is thrown only when I run all test in solution, when I run the test in isolation from its class it passes.

As an example I have a test method for a similar controller that does actually pass, below is the code for the test method and its route:

The Test Method

    [TestMethod]
    public void HVM_Route_Maps_to_HVMController()
    {
        "~/hvm/".ShouldMapTo<HVMController>(action => action.Index());
    }

The Route:

routes.MapRoute(
            name: "HVM",
            url: "hvm/",
            defaults: new { controller = "HVM", action = "Index" }
        );

this test produces no error.

Was it helpful?

Solution

When I had refactored the tests to add the route registration to an [AssemblyInitialize] method I had forgotten to remove a [TestCleanup] method from one of the unit test classes causing the route to be re-registered.

After removing this all tests passed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top