测试失败时"在解决方案&QUOT运行所有测试;用来 [英] tests failing when "Run All Test in Solution" is used

查看:236
本文介绍了测试失败时"在解决方案&QUOT运行所有测试;用来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让单元测试来为我的MVC 4 Web应用程序项目成功运行。

I am trying to get unit tests to run successfully for my MVC 4 Web Application project.

当我单独运行测试类中的所有测试都通过了,当我来到运行解决方案仅2/9合格,我点击调试经过测试,他们全部通过,当我命中再次运行,他们也都所有测试通过。

When I run the tests classes individually all of the tests pass, when I come to run all test in solution only 2/9 pass, I have clicked Debug Checked Tests and they all pass when I the hit run again they also all pass.

这个问题,当我检查项目到TFS也被复制的,我有自己的项目设置连续集成构建,运行测试,失败完全相同的测试。

This problem is also being replicated when I check the project into TFS, I have setup continuous integration they project builds, runs the tests and fails on exactly the same tests.

我得到的回复是错误的 *命名为''A路线已经是路由集合在

The error I'm getting back is *"A route named '' is already in the route collection"

没有任何人有任何想法,为什么这可能发生?

Does anybody have any ideas why this might be happening?

在每个类我有一个[TestInitialize]块,如下图所示:

In each class I have a [TestInitialize] block which is shown below:

[TestInitialize]
public void Setup()
{
    var builder = new TestControllerBuilder();
    controller = new MyController();
    builder.InitializeController(controller);

    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

我曾在班一个类似的错误,当我还没有包括TestControllerBuilder,会不会是这个code未正常运行?

I had a similar error in the classes when I hadn't included the TestControllerBuilder, could it be that this code is not running correctly?

推荐答案

RouteTable.Routes 是静态的,因此将只每个AppDomain初始化一次。

RouteTable.Routes is static and therefore will only be initialized once per AppDomain.

所以,每次运行测试时间,你实际上是试图一次又一次重新注册相同的路线。

So every time you run a test, you are in effect trying to re-register the same routes over again.

您可能会更好过移动路线注册成<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assemblyinitializeattribute%28v=vs.110%29.aspx\"相对=nofollow> AssemblyInitialize 属性,以便它只会在整个测试运行开始运行一次。

You would probably be better off moving your route registration into an AssemblyInitialize attribute so it will only run once at the beginning of the entire test run.

这篇关于测试失败时&QUOT;在解决方案&QUOT运行所有测试;用来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆