多次运行UnitTest-不只是循环 [英] Run UnitTest several time - not just loop it

查看:131
本文介绍了多次运行UnitTest-不只是循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS UnitTest(MSTest)来介绍一些多线程代码.如果没有所需的锁,则代码将无法通过30次运行(即运行的一半)进行测试.我修复了代码,测试通过了30次.

I have a VS UnitTest (MSTest) to cover some multiple threading code. With out the required locks the code fails the test 15 out 30 runs - i.e half the runs. I fix the code and the tests pass 30 times.

现在,我希望测试框架能够运行N次测试,而不仅仅是一次测试,以确保运气不会一次通过.似乎没有任何方法可以对测试中的属性执行此操作,因此我在测试内部放置了一个循环以运行测试代码主体N次.

Now I want the test framework to run the test N time and not just once to be sure that it cant pass once out of luck. There doesn't seem to be any way to do that with an attribute on the test so I put a loop INSIDE the test to run the test code body N times.

我删除了对代码的修复(锁等)并运行测试(循环N次)-并通过了测试.我再次运行它(循环N次),但它失败了……我回到了我开始的地方-它仍然仅失败了一半的时间(即使它在每个测试中都经过了N次测试主体).

I remove the fixes to the code (locks etc) and run the test (which loops N times) - and bam it passes. I run it again (loop N times) and it fails... Im back where I started - its still failing only half the time (even though its doing N loops through test body on each test).

我真正想要的不是在测试内部循环,而是真正让测试框架加载测试,运行测试,卸载测试等N次(就像我最初手工所做的那样). (为什么不只是为此一个测试属性-如[TestRepeatCount=5]?)

What I really want is not to loop inside the test but really have the test framework load the test, run test, unload test etc N times (as I did by hand originally). How to do that? (Why isn't there just a test attribute for this - like [TestRepeatCount=5]?)

推荐答案

您真正需要的是负载测试.添加您的单元测试并对其进行配置.

What you really need is a Load Test. Add your unit test(s) and configure it how it will run.

您可以设置测试总数,并发测试数等.

You can set the number of total tests, the number of concurrent tests e.t.c.

这篇关于多次运行UnitTest-不只是循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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