0

与可以在此处找到的先前问题相关:

使用“在解决方案中运行所有测试”时测试失败

测试方法:

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

}

路线:

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

返回的错误:

测试方法 MBS.Exec.Enquiry.MVC.Tests.AMACControllerTest.AMAC_Route_Maps_to_AMACController 抛出异常:MvcContrib.TestHelper.AssertionException:URL 不匹配任何路由

仅当我在解决方案中运行所有测试时,才会抛出此错误,当我独立于其通过的类运行测试时。

作为一个例子,我有一个类似控制器的测试方法,它确实通过了,下面是测试方法的代码及其路由:

测试方法

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

路线:

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

此测试不会产生错误。

4

1 回答 1

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.

于 2013-01-31T10:38:05.293 回答