【问题标题】:Where is the [TestMethod] Attribute in TypeMock?TypeMock 中的 [TestMethod] 属性在哪里?
【发布时间】:2009-07-17 12:48:34
【问题描述】:

好的,愚蠢的问题。我正在尝试在 VS2005 中设置我的第一个 TypeMock 演示项目,但它无法识别 [TestMethod] 属性。我已经包含了 TypeMock 和 TypeMock.ArrangeActAssert 程序集,并且我用“使用”语句来引用它们。即使是智能感知也找不到该属性。我在这里做错了什么?

【问题讨论】:

    标签: c# .net testing typemock


    【解决方案1】:

    [TestMethod] 来自 Visual Studio 单元测试“框架”。 下面的代码基本上展示了如何使用该属性:

        using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    [TestClass]
    public class MyTests
    {
        [TestMethod]
        public void MyFirstTest()
        {
            Assert.AreEqual(1, 1);
        }
    }
    

    如果您使用的是 NUnit 或其他框架,属性可能会有所不同。

    【讨论】:

      【解决方案2】:

      您使用的是哪个单元测试框架? TestMethod 听起来像 Visual Studio test 系统,而 NUnit 对应的系统称为 Test

      【讨论】:

        【解决方案3】:

        我猜测 TestMethodAttribute 来自 MSTest,而不是 TypeMock。 所以你应该添加对 Microsoft.VisualStudio.QualityTools.UnitTestFramework 的引用

        编辑: 这是定义属性的命名空间: Microsoft.VisualStudio.TestTools.UnitTesting;

        【讨论】:

          【解决方案4】:

          [TestMethod] 来自 MSTest 库而非 TypeMock 框架

          【讨论】:

          • 啊,现在我明白了。我的印象是 TypeMock 本身就是一个完整的模拟/单元测试框架。谢谢!
          【解决方案5】:

          假设您使用的是 MSTest,则必须为类包含 [TestClass()],为测试包含 [TestMethod()](不知道是否需要括号)。

          TypeMock 是一个模拟框架,因此您应该首先担心您使用的是什么测试框架。

          【讨论】:

            猜你喜欢
            • 2014-12-25
            • 1970-01-01
            • 1970-01-01
            • 2015-12-08
            • 1970-01-01
            • 2018-04-11
            • 1970-01-01
            • 1970-01-01
            • 2022-09-27
            相关资源
            最近更新 更多