简体   繁体   English

如何使单元测试在Visual Studio中连续运行

[英]How do I get unit tests to run continuously in Visual Studio

Maybe I'm using unit tests in the wrong way, but I have a very large database with a lot of data. 也许我以错误的方式使用了单元测试,但是我有一个包含大量数据的超大型数据库。

Each set of data presents a different scenario and the number of scenarios is too large to individually test. 每组数据表示不同的方案,方案的数量太大,无法单独测试。 Therefore, I've decided the best way to get adequate coverage is to run the unit test against the data as many times as I could, and see if it will break and if it does, work out why it's happening. 因此,我决定获得足够覆盖率的最佳方法是对数据进行单元测试,次数尽可能多,看看它是否会破裂,如果破裂,找出原因。

The problem is in Visual Studio 2008, I can't figure out how to run a unit test more than once. 问题是在Visual Studio 2008中,我无法弄清楚如何多次运行单元测试。 Is that possible? 那可能吗? Is it possible to tell VS2008 to run and re-run my unit tests continuously over the course of a period of time. 是否可以告诉VS2008在一段时间内连续运行并重新运行我的单元测试。

If you don't mind breaking from the mold of having text code run straight down from start to end with no branching. 如果您不介意让文本代码从头到尾直接运行而没有分支的话,那您就不介意了。 Your data driven tests can still be driven by some kind of code in a unit test. 您的数据驱动测试仍可以由单元测试中的某种代码驱动。 In visual studio there are setup methods and tear down methods you can employ. 在Visual Studio中,可以使用设置方法和拆卸方法。 You could also simply put code in your test methods that loop the data testing various combinations. 您也可以简单地将代码放入测试方法中,以循环测试各种组合的数据。 But a general rule of thumb in low level unit tests is to have no complicated logic branching. 但是低级单元测试的一般经验法则是没有复杂的逻辑分支。 Today I was just writing some unit tests (Working late again... I know, but I couldn't break away from the computer) and I took the opportunity to unroll some for loops. 今天,我只是在编写一些单元测试(再次工作到很晚……我知道,但是我无法摆脱计算机的束缚),我借此机会展开了一些循环测试。 Simply because I didn't want any complexity in the test methods. 仅仅是因为我不想测试方法有任何复杂性。 But for data driven testing, I don't see any alternative. 但是对于数据驱动的测试,我没有其他选择。

EDIT: Sorry, but I don't have VS 2008 on this computer but I do have VS 2010. 1. In the solution explorer find your unit test configuration file. 编辑:对不起,但是我在这台计算机上没有VS 2008,但是我确实有VS2010。1.在解决方案资源管理器中,找到您的单元测试配置文件。 In VS 2010 it's called local.testsetting 2. Double click it to bring up it's properties. 在VS 2010中,它称为local.testsetting 2.双击它以显示其属性。 3. The closest thing I found is on the 'Web Test' dialog there is a spinner value labeled "Fixed Run Count" that allows you to specificy how many times to peform a particular test run. 3.我找到的最接近的结果是在“ Web测试”对话框上,有一个标为“固定运行次数”的微调器值,它使您可以指定执行特定测试运行的次数。

This may not be the best answer, but you pose a good question. 这可能不是最佳答案,但是您提出了一个很好的问题。

In case this is useful to anyone else, you can use an ordered test to run the same test multiple times. 如果这对其他人有用,则可以使用有序测试多次运行同一测试。

From the test menu, select new test and add an ordered test. 从测试菜单中,选择新测试并添加有序测试。 You can then add the same test to your ordered test multiple times. 然后,您可以多次将同一测试添加到订购的测试中。 Note the Continue after failure option in the bottom left of the ordered test window. 请注意有序测试窗口左下方的失败后继续选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio中分别在不同的文件夹/项目中运行(单元)测试? - How do I run (unit) tests in different folders/projects separately in Visual Studio? 如何在 Visual Studio 2017/2019 中为特定目标框架运行单元测试? - How do you run unit tests for a specific target framework in Visual Studio 2017/2019? 如何使Visual Studio不等待临时阻止的测试? - How do I get visual studio to not wait on temporarily blocked tests? 在Visual Studio中运行应用程序时如何运行单元测试 - How to run unit tests when running the application in visual studio 在Visual Studio中运行JavaScript单元测试 - Run JavaScript unit tests inside of Visual Studio 如何在Visual Studio 2013上为单元测试设置Emgu CV? - How do I set up Emgu CV on Visual Studio 2013 for Unit Tests? 如何在命令行中运行通常在Visual Studio测试资源管理器中运行的.cs测试? - How do I run .cs tests that I normally run in the Visual Studio Test Explorer, in the command line? 如何在 Visual Studio 中为 Xamarin 项目创建单元测试? - How can I create unit tests for a Xamarin project in Visual Studio? 单元测试Visual Studio - Unit Tests Visual Studio 如何在带有Visual Studio 2017和NUnit 3的MacOsX中运行测试? - How do I can run tests in MacOsX with Visual Studio 2017 and NUnit 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM