为什么使用此代码 MSTest 和 TestDriven.NET 的行为不同?

发布于 2024-07-13 08:02:30 字数 792 浏览 4 评论 0原文

查看此代码:

internal static readonly Dictionary<Type, Func<IModel>> typeToCreator = new Dictionary<Type, Func<IModel>>();
protected static object _lock;        


public virtual void Register<T>(Func<IModel> creator)
{
    lock (_lock)
    {
    if (typeToCreator.ContainsKey(typeof(T)))
        typeToCreator[typeof(T)] = creator;
    else
        typeToCreator.Add(typeof(T), creator);
    }
}

当我在该测试中运行代码时(testframework 是 MSTest):

[TestMethod]
public void Must_Be_BasePresenterType()
{
     var sut = new ListTilbudPresenter(_tilbudView);
     Assert.IsInstanceOfType(sut, typeof(BasePresenter));
}

...MSTest 通过了它,而 TestDriven.NET 失败了,因为 _lock 为 null。

为什么 MSTest 没有通过测试???

Check out this code:

internal static readonly Dictionary<Type, Func<IModel>> typeToCreator = new Dictionary<Type, Func<IModel>>();
protected static object _lock;        


public virtual void Register<T>(Func<IModel> creator)
{
    lock (_lock)
    {
    if (typeToCreator.ContainsKey(typeof(T)))
        typeToCreator[typeof(T)] = creator;
    else
        typeToCreator.Add(typeof(T), creator);
    }
}

When I use run the code in this test (testframework is MSTest):

[TestMethod]
public void Must_Be_BasePresenterType()
{
     var sut = new ListTilbudPresenter(_tilbudView);
     Assert.IsInstanceOfType(sut, typeof(BasePresenter));
}

...MSTest passes it and TestDriven.NET fails it because _lock is null.

Why does MSTest NOT fail the test???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文