0

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.

Community
  • 1
  • 1
CryoFusion87
  • 796
  • 1
  • 8
  • 28
  • possible duplicate of [tests failing when "Run All Test in Solution" is used](http://stackoverflow.com/questions/14605580/tests-failing-when-run-all-test-in-solution-is-used) – Darin Dimitrov Jan 31 '13 at 09:20
  • any workarounds I have a rather large number of controllers each with there own corresponding route, would it be best to test one at a time or could I write a test that checks whether all routes map to each of their controllers – CryoFusion87 Jan 31 '13 at 09:54
  • You should register the routes only once, ideally inside a method decorated with the `[AssemblyInitialize]` attribute as already answered in your previous question. – Darin Dimitrov Jan 31 '13 at 10:01
  • already done, I have a separate class that contains the AssemblyIntialize method called RouteRegistration, before I had implemented this all but two tests failed now only one out of 9 fails, have commented out the test method that is causing the issue and all pass like wise have uncommented the amac test and commented out hvm and again all pass – CryoFusion87 Jan 31 '13 at 10:06
  • I have another similar test for another route and controller that I have left in that so far has not failed when I have commented out one of the other two tests as mentioned above – CryoFusion87 Jan 31 '13 at 10:30

1 Answers1

0

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.

CryoFusion87
  • 796
  • 1
  • 8
  • 28