[ClassInitialize()] [ClassCleanup()] [TestInitialize()] [TestMethod] [TestCleanup()]
在执行一个或多个[TestMethod]输出时, [ClassInitialize()] 最先执行,[ClassCleanup()]最后执行,对于执行每个[TestMethod],执行顺序是[TestInitialize()] [TestMethod] [TestCleanup()]

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
static StreamWriter sw = new StreamWriter("C:\\temp\\Test.txt", false);
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
sw.WriteLine("MyClassInitialize");
sw.Flush();
}
[ClassCleanup()]
public static void MyClassCleanup()
{
sw.WriteLine("MyClassCleanup");
sw.Flush();
} [TestInitialize()]
public void MyTestInitialize()
{
sw.WriteLine("MyTestInitialize");
sw.Flush();
}
[TestCleanup()]
public void MyTestCleanup()
{
sw.WriteLine("MyTestCleanup");
sw.Flush();
}
[TestMethod]
public void TestMethod1()
{
sw.WriteLine("TestMethod1");
sw.Flush();
}
[TestMethod]
public void TestMethod2()
{
sw.WriteLine("TestMethod2");
sw.Flush();
}
[TestMethod]
public void TestMethod3()
{
sw.WriteLine("TestMethod3");
sw.Flush();
}
}
}

3个method一起选中执行的输出

MyClassInitialize

MyTestInitialize
TestMethod1
MyTestCleanup

MyTestInitialize
TestMethod2
MyTestCleanup

MyTestInitialize
TestMethod3
MyTestCleanup

MyClassCleanup

选中一个,执行后的输出

MyClassInitialize
MyTestInitialize
TestMethod1
MyTestCleanup
MyClassCleanup

Unit Test测试框架中的测试的执行顺序的更多相关文章

  1. selenium 测试框架中使用grid

    之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...

  2. IOS(SystemConfiguration)框架中关于测试连接网络状态相关方法

    1. 在SystemConfiguration.famework中提供和联网相关的function, 可用来检查网络连接状态. 2. SC(SystemConfiguration)框架中关于测试连接网 ...

  3. <自动化测试>之<使用unittest Python测试框架进行参数化测试>

    最近在看视频时,虫师简单提到了简化自动化测试脚本用例中的代码量,而python中本身的参数化方法用来测试很糟糕,他在实际操作中使用了parameterized参数化... 有兴趣就查了下使用的方法,来 ...

  4. SQL 中 SELECT 语句的执行顺序

    好像自已在书写 SQL 语句时由于不清楚各个关键字的执行顺序, 往往组织的 SQL 语句缺少很好的逻辑, 凭感觉 "拼凑" ( 不好意思, 如果您的 SQL 语句也经常 " ...

  5. SQLServer2005中查询语句的执行顺序

    SQLServer2005中查询语句的执行顺序   --1.from--2.on--3.outer(join)--4.where--5.group by--6.cube|rollup--7.havin ...

  6. 容易被忽略的事----sql语句中select语句的执行顺序

    关于Sql中Select语句的执行顺序,一直很少注意这个问题,对于关键字的使用也很随意,至于效率问题,因为表中的数据量都不是很大,所以也不是很在意. 今天在一次面试的时候自己见到了,感觉没一点的印象, ...

  7. MySQL-SQL语句中SELECT语句的执行顺序

    SELECT语句的执行顺序大家比较少关注,下面将为您详细介绍SQL语句中SELECT语句的执行顺序,供您参考,希望对您能够有所帮助. SELECT语句的执行的逻辑查询处理步骤: (8)SELECT ( ...

  8. mysql 中sql语句的执行顺序

    今天突然想起来,之前面试一个很牛逼的公司(soho)的时候,一个美眉面试官,面试的时候问到了很多之前都没有意识到的问题,回想起来那美眉看着年纪不大,技术那是真666啊.好了说一下人家问的这个有关mys ...

  9. 在Spring Bean的生命周期中各方法的执行顺序

    Spring 容器中的 Bean 是有生命周期的,Spring 允许在 Bean 在初始化完成后以及 Bean 销毁前执行特定的操作,常用的设定方式有以下十种: 通过实现 InitializingBe ...

随机推荐

  1. 关于checkbox的全选和反选实例

    <script type="text/javascript"> $(function () { $("#checkAll").click(funct ...

  2. SharePoint 2013 文档库中PPT转换PDF

    通过使用 PowerPoint Automation Services,可以从 PowerPoint 二进制文件格式 (.ppt) 和 PowerPoint Open XML 文件格式 (.pptx) ...

  3. 关于Fragment你所需知道的一切!

    转载自刘明渊 的博客地址:http://blog.csdn.net/vanpersie_9987 Fragment 是 Android API 中的一个类,它代表Activity中的一部分界面:您可以 ...

  4. iOS面试题总结 (二)

    14 OC的理解和特性 OC作为一个面向对象的语言,他也就具有面向对象的特点-封装,继承,多态. OC是一门动态性的语言,他具有动态绑定,动态加载,动态类型.动态即就是在运行时才会做的一些事情. 动态 ...

  5. MD5工具类

    package com.liu.hellomavenweb.util; import java.security.MessageDigest; /** * * @author 刘楠 * */ publ ...

  6. select、poll、epoll区别总结

    1 本质上都是同步I/O 三者都是I/O复用,本质上都属于同步I/O.因为三者只是负责通知应用程序什么时候数据准备好了,实际的I/O操作还是在由应用程序处理:如果是异步I/O的话,实际I/O由内核处理 ...

  7. [css]我要用css画幅画(九) - Apple Logo

    接着之前的[css]我要用css画幅画(八) - Hello Kitty,这次画的是苹果公司的logo 这次打算将分析和实现步骤尽量详细的说一说. 其实之前的也打算详细讲分析和设计过程,不过之前的图比 ...

  8. curl操作CouchDB

    couchdb 服务器地址: 127.0.0.1 端口:5984 添加数据库 连接到couchdb curl -X GET http://127.0.0.1:5984 {"couchdb&q ...

  9. Create view failed with ORA-01031:insufficient privileges

    有时候在ORACLE数据库创建视图时会遇到:ORA-01031:insufficient privileges错误,我也多次碰到了各种创建视图出错的情况,很多时候也没有太在意,今天被一同事问起这个问题 ...

  10. (转载)SQL Reporting Services (Expression Examples)

    https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...