如何为 Visual Studio 测试项目创建启动和清理脚本? [英] How to create Startup and Cleanup script for Visual Studio Test Project?

查看:17
本文介绍了如何为 Visual Studio 测试项目创建启动和清理脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 测试项目,正在使用部署文件等修改测试配置(通过 VS GUI),现在我需要为测试运行编写启动脚本.

I'm using a Visual Studio Test project, am modifying the test config with deployment files, etc. (through the VS GUI) and now I need to write a Startup script for the test run.

我不知道这些脚本使用什么语言或文件类型或机制.需要小费.

I have no clue what language or file type or mechanism is used for these scripts. Need a tip.

推荐答案

在您的测试项目中创建一个单元测试.在单元测试类中,创建具有 [TestInitialize][TestCleanup] 属性的方法.它们将在每个测试方法之前/之后运行.

Create a unit test in your test project. In the unit test class, create methods with the [TestInitialize] and [TestCleanup] attributes. They will be run before/after each test method.

或者,如果您想在该类中的所有测试之前/之后运行,请创建具有 [ClassInitialize][ClassCleanup] 属性的静态方法.

Or, if you want to run before/after all test in that class, create static methods with [ClassInitialize] and [ClassCleanup] attributes.

最后,要在程序集中的所有测试之前/之后运行,请使用 [AssemblyInitialize][AssemblyCleanup] 属性创建静态方法.

Lastly, to run before/after all tests in the assembly, create static methods with [AssemblyInitialize] and [AssemblyCleanup] attributes.

这篇关于如何为 Visual Studio 测试项目创建启动和清理脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆