代码之家  ›  专栏  ›  技术社区  ›  Adam Kane

VisualStudio.TestTools.WebTesting.TestDescriptionAttribute语法

  •  0
  • Adam Kane  · 技术社区  · 15 年前

    使用测试的[TestDescriptionAttribute][1]填充测试结果窗口中的描述列的语法是什么?

    上下文:Visual Studio 2008 Team System

    我已经阅读了文档,但找不到具体的示例。

    根据Ngu的建议,我尝试了:

    using GlobalSim;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    
    namespace GlobalSimTests {
    
        /// <summary>
        ///This is a test class for PongerTest and is intended
        ///to contain all PongerTest Unit Tests
        ///</summary>
        [TestClass()]
        [TestDescriptionAttribute( "hello" )]
        public class PongerTest {
    
            private TestContext testContextInstance;
    
            /// <summary>
            ///Gets or sets the test context which provides
            ///information about and functionality for the current test run.
            ///</summary>
            public TestContext TestContext {
                get {
                    return testContextInstance;
                }
                set {
                    testContextInstance = value;
                }
            }
    
            /// <summary>
            ///A test for Ping
            ///</summary>
            [TestMethod()]
            public void PingTest () {
                Ponger target = new Ponger();
                string expected = "Pong";
                string actual;
                actual = target.Ping();
                Assert.AreEqual( expected, actual );
            }
    
        }
    }
    

    这会编译,但不会在“测试结果”窗口的“描述”列中显示测试描述。

    alt text

    我也尝试过这种语法:

        /// <summary>
        ///A test for Ping
        ///</summary>
        [TestMethod()]
        [TestDescription( "hello" )]
        public void PingTest () {
            Ponger target = new Ponger();
            string expected = "Pong";
            string actual;
            actual = target.Ping();
            Assert.AreEqual( expected, actual );
        }
    

    从编译器返回:

    属性“testdescription”在此声明类型上无效。它只对“class”声明有效。

    这是有效的语法。谢谢大家!

        /// <summary>
        ///A test for Ping
        ///</summary>
        [TestMethod()]
        [Description( "Hello" )]
        public void PingTest () {
            Ponger target = new Ponger();
            string expected = "Pong";
            string actual;
            actual = target.Ping();
            Assert.AreEqual( expected, actual );
        }
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   shahkalpesh    15 年前

    正如@ngu所说,把它放在 测试 方法

    [TestMethod()]
    [Description( "PingTest Check" )]
    public void PingTest () {
         Ponger target = new Ponger();
         string expected = "Pong";
         string actual;
         actual = target.Ping();
         Assert.AreEqual( expected, actual );
      }
    

    编辑: TestDescriptionAttribute 是来自 WebTesting 命名空间,不应将其应用于单元测试。使用 DescriptionAttribute 相反,它是 UnitTesting 命名空间。

    请参阅上面修改的代码,我确信它会起作用。

    edit2:要查找类似的内容,请查看同一命名空间中的类。这就是类的排列方式,这样人们可以很容易地找到它。

        2
  •  -1
  •   Graviton    15 年前
    TestDescriptionAttribute(TestDescription="hi")
    

    因此,对于那个特定的测试,描述将是 hi .

    把它放在方法的顶部,看看它是否有效。