经典性能测试程序范例(MSTest单元测试框架速查表)
经典性能测试程序范例(MSTest单元测试框架速查表)using Microsoft.VisualStudio.TestTools.UnitTesting; namespace MSTestUnitTests { // A class that contains MSTest unit tests. (Required) [TestClass] public class YourUnitTests { [AssemblyInitialize] public static void AssemblyInit(TestContext context) { // Executes once before the test run. (Optional) } [ClassInitialize] p
.NET下的单元测试框架主要有NUnit、XUnit,以及微软自家的MS Test。
很明显,NUnit更加好用一些,不过大多数时候微软自家的MS Test也足够了,基本的功能都差不多,应付小型的单元测试足够了,而且Visual Studio内置MS Test。
想要快速了解MSTest Unit Testing Framework Cheat Sheet,可以下载这份cheetsheet,包含了MSTest的常见用法,感兴趣的朋友可以私信获取。
这是最关键的测试方法
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MSTestUnitTests
{
    // A class that contains MSTest unit tests. (Required)
    [TestClass]
    public class YourUnitTests
    {
        [AssemblyInitialize]
        public static void AssemblyInit(TestContext context)
        {
            // Executes once before the test run. (Optional)
        }
        [ClassInitialize]
        public static void TestFixtureSetup(TestContext context)
        {
            // Executes once for the test class. (Optional)
        }
        [TestInitialize]
        public void Setup()
        {
            // Runs before each test. (Optional)
        }
        [AssemblyCleanup]
        public static void AssemblyCleanup()
        {
            // Executes once after the test run. (Optional)
        }
        [ClassCleanup]
        public static void TestFixtureTearDown()
        {
            // Runs once after all tests in this class are executed. (Optional)
            // Not guaranteed that it executes instantly after all tests from the class.
        }
        [TestCleanup]
        public void TearDown()
        {
            // Runs after each test. (Optional)
        }
        // Mark that this is a unit test method. (Required)
        [TestMethod]
        public void YouTestMethod()
        {
            // Your test code goes here.
        }
    }
}
    

测试方






有些考试时可以带一张小抄,通常老师会规定它的大小,或是单面双面等等,至于字要多小那是自己的事情。这张小抄就叫 cheat sheet (故名思议,作弊用纸)。
计算机编程领域中经常将关于某些关键知识点集中起来,也称其为cheat sheet,如果翻译为作弊用纸的话,带有贬义的意思,因此一般称其翻译为速查表,快速参考。




