测试在本地失败,但在服务器

时间:2015-08-20 09:24:39

标签: c# unit-testing tfs tfs2010 simple-injector

我们在WebAPI项目上进行了以下单元测试:

[TestMethod]
[TestCategory("UnitTests.InternalAPi")]
[TestCategory("ContainerConfigTests")]
[TestCategory("ContainerConfigTests.RegisterComponents")]
public void ContainerVerified()
{
    // HACK: This isn't really a unit test per se, it's testing components that we're not 
    // directly interested in. However, it exists to provide an early warning that the 
    // container config would fail at runtime.

    var container = new Container();

    ContainerConfig.RegisterApplicationComponents(container);

    container.Verify();

    // An Exception will be thrown if the container does not verify correctly.
    Assert.IsTrue(true); 
}

此测试的目的是执行API执行的DI注册(或者我们创建的所有类,至少 - 它跳过Controller注册等),然后验证一切正常。

如果缺少注册,则此测试将在本地VS实例上按预期失败(它会引发异常,导致测试失败)。但是,它在服务器上不会失败。

TFS上的TestResult文件的输出表明此测试确实已运行,并且已通过。

可能导致此问题的原因是什么?

更新

由于我们的一些内部要求,此解决方案的实际设置有点复杂,但此设置的说明如下:

  • 解决方案1 ​​

    • 核心项目
      • 包含要注册的界面
    • 实施项目
      • 包含接口实现
      • 项目参考核心
  • 解决方案2

    • 核心项目
      • 包含要注册的界面
    • API项目
      • 项目参考核心
      • Dll参与实施
    • 测试项目
      • 项目参考核心
      • 项目参考API
      • Dll Ref to Implementation

API方法

public class ContainerConfig
{
  public static void RegisterApplicationComponents(Container container)
  {
    container.Register<ICoreInterface, Implementation.Implementation>();
  }
}

重现步骤

  1. Open Solution 2
  2. 使用新方法更新核心界面
  3. 构建解决方案2
  4. 运行验证单元测试
  5. 本地验证失败
  6.   

    测试名称:ContainerVerified   测试FullName:UnitTests.UnitTest1.ContainerVerified   测试源:d:\ Users \ freilly \ documents \ visual studio 2015 \ Projects \ WebApi \ UnitTests \ UnitTest1.cs:第16行   测试结果:失败   测试时间:0:00:00.0951898

         

    结果StackTrace:   at WebApi.App_Start.ContainerConfig.RegisterApplicationComponents(Container container)      位于D:\ Users \ freilly \ documents \ visual studio 2015 \ Projects \ WebApi \ UnitTests \ UnitTest1.cs中的UnitTests.UnitTest1.ContainerVerified():第23行   结果消息:   测试方法UnitTests.UnitTest1.ContainerVerified抛出异常:   System.TypeLoadException:Method&#39; TestFailureMethod&#39;在类型&#39; Implementation.Implementation&#39;来自assembly&#39; Implementation,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null&#39;没有实施。

    1. 提交更改 - CI构建的测试通过

0 个答案:

没有答案