如何从命令行告诉我的 (MSTest) 测试列表以两种模式之一运行?
我有一些测试基本上以两种模式运行。一种模式针对最少的数据运行,这些模式旨在在每次提交后运行。另一种模式针对大量数据运行,这些模式旨在每晚运行。
现在,我使用 vsmdi 文件将测试分成按提交和每晚命名的不同列表,并且我的构建服务器使用 vsmdi 文件和测试列表名称通过命令行调用它们。为此,我必须创建两个不同的 [TestMethod] 函数,一个用于每次提交模式,一个用于夜间模式。然后我当然将它们分配到两个列表之一。
我认为这有点乏味..我知道你不允许将参数传递到测试方法中,但是有没有办法配置测试类,以便每个测试了解它试图运行的模式?此配置需要以某种方式通过命令行传递,以便构建服务器正常工作,如果我还可以在任何给定点将 Visual Studio 配置为一种模式或另一种模式,或两种模式都模式,那就太好了,以便测试运行键盘快捷方式可以正常工作。
I have certain tests that are basically run in two modes. One mode runs against minimal data, these are intended to be run after every commit. The other mode runs against extensive data, these are intended to be run nightly.
Right now, I'm using the vsmdi file to split my tests into different lists named per commit and nightly, and my build server calls them through the command line using the vsmdi file and the test list name. For this to work, I have to make two different [TestMethod] functions, one for the per commit mode and one for the nightly mode. Then I of course assign them to one of the two lists.
I thought this was a little tedious.. I know you're not allowed to pass parameters into your test methods, but is there a way to configure the test class so that each test understands what mode it's trying to run in? This configuration needs to be passed through the command line somehow so the build server works, and it would be nice if I could also configure visual studio to be in one mode or the other, or both, at any given point so the test running keyboard shortcuts work right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在单元测试中使用 MsTest Category Attribute 来实现此目的。
您可以在每个测试中放置多个类别,以便您可以混合搭配。然后,您可以从命令行使用
/category
开关运行测试,并再次选择要运行的测试。查看此链接。You can acheive this by using MsTest Category Attribute on your unit tests.
You can place more than one category on each test, so you can mix and match. Then from the command line you can run the tests with the
/category
switch and again choose which tests to run. Check out this link.如果您的“大量”数据集运行时间过长,那么您的数据集可能存在问题。您应该能够用快速运行的最小数据集涵盖所有测试用例。这是我的轶事:我曾经写过一些东西来生成 USPS 条形码。 USPS 非常友善地提供了 10,000 个测试用例及其预期结果。我尽职尽责地将这 10,000 个测试用例转变为单独的单元测试。然而,我很快意识到这 10,000 个测试用例很大程度上是多余的,实际上只有几十个实际测试用例 - 其余的都是噪音。我怀疑你的情况就是这样。您正在使用大型数据集进行测试,而可以使用较小的数据集进行测试。
当然,除非测试用例是您的应用程序在处理大型数据集时的行为方式。在这种情况下,将您的测试分成两个程序集,并将您的构建配置为仅在每次签入时运行“快速”测试程序集,并将您的夜间构建配置为运行这两个程序集。
If your "extensive" dataset is taking too long to run, then you probably have a problem with your dataset. You should be able to cover all of your test cases in a minimal set of data that runs quickly. Here's my anecdote: I once wrote something to generate USPS barcodes. The USPS very kindly provided 10,000 test cases and their expected results. I dutifully turned these 10,000 test cases into individual unit tests. However, I quickly realized that those 10,000 test cases were largely redundant, and there were really only a couple of dozen actual test cases -- the rest were noise. That's what I suspect is going on in your case. You're testing with a large dataset what could be tested with a much smaller one.
Unless, of course, the test case is how your application behaves when processing a large dataset. In that case, split your tests into two assemblies, and configure your build to only run the "quick" test assembly on every checkin, and your nightly build to run both.