c# - Can I set up a unit test to run many times and return the percentage success? -
i new unit testing, , have been scouring web, trying figure out how further automate unit tests. building registration scheme, , want test variety of hard drive serial numbers, app numbers, etc. want generate registration key , check make sure decodes properly. looking automate running test (with integrated visual studio test environment) variety of inputs, , after thousands of runs, find out % of tests successful , unsuccessful. possible? below test method:
[testmethod] public void generatingvalidkeytest() { int numreaddevices; string appnum = "123"; string hddserial = "1234567890"; string numdevices = "12"; string regnumber = registration.generatekey(appnum, numdevices, hddserial); assert.istrue(registration.checkkey(regnumber, appnum, out numreaddevices, hddserial), "generated key not pass check."); assert.areequal(int.parse(numdevices), numreaddevices,"number of registered devices not match requested number"); }
if use nunit can set series of valuesources feed method.
if have separate value source appnum, hddserial , numdevices, you'll appnum * hddserial * numdevices number of tests.
you shouldn't aiming find percentage of tests pass, though. purpose of unit testing ensure test scenarios pass.
to take max's example , make valuesources:
[test] public void dividetest([valuesource("appnums")]string appnum, [valuesource("serials")]string hddserial, [valuesource("numdevices")]string numdevices) { string regnumber = registration.generatekey(appnum, numdevices, hddserial); assert.istrue(registration.checkkey(regnumber, appnum, out numreaddevices, hddserial), "generated key not pass check."); assert.areequal(int.parse(numdevices), numreaddevices,"number of registered devices not match requested number"); } static object[] appnums = { "1", "2", "3", "4", "5", "6", "7" }; static object[] serials = { "example", "another", "and again" }; static object[] numdevices = { "1", "2", "3", "4", "5", "6", "7" };
Comments
Post a Comment