Nunit-C#: run specific Tests through coding -


i using selenium c# automation, , want invoke nunit through code follows:

coreextensions.host.initializeservice(); testpackage testpackage = new testpackage(@"d:\automation\bin\debug\test.dll"); remotetestrunner remotetestrunner = new remotetestrunner(); remotetestrunner.load(testpackage); //testfilter filter = new namefilter(new testname() { name = "test1" }); testresult testresult = remotetestrunner.run(     new nulllistener(),     testfilter.empty,     false,     loggingthreshold.off );  

i able run tests using category filter below

remotetestrunner.run(     new nulllistener(),     new categoryfilter("mycat"),     false,     loggingthreshold.off ); 

but want execute specific tests. how set suite filter? have tried following, not work:

testfilter filter = new namefilter(new testname() { name = "test1" });  testresult testresult = remotetestrunner.run(     new nulllistener(),     filter,     false,     loggingthreshold.off ); 

how run specific tests , how pass arguments through code?

this sample code should give idea of have start cycling through tests , selecting 1 want run. have used several array indexes of 0 should loop through instead.

the jist of have load tests before can start trying run them individually tests need have unique testid gets set once have been loaded. following code works , runs first test in first testfixture in testing framework. scans test names either display or run based on criteria

coreextensions.host.initializeservice(); testsuitebuilder builder = new testsuitebuilder(); testpackage testpackage = new testpackage(@"path.to.dll"); remotetestrunner remotetestrunner = new remotetestrunner(); remotetestrunner.load(testpackage); testsuite suite = builder.build(testpackage); testsuite test = suite.tests[0] testsuite; var numberoftests = ((testfixture)test.tests[0]).testcount;  foreach (testmethod t in ((testfixture)test.tests[0]).tests) {     console.writeline(t.testname.name); }  testname testname = ((testmethod)((testfixture)test.tests[0]).tests[0]).testname; testfilter filter = new namefilter(testname); testresult result = test.run(new nulllistener(), filter); resultsummarizer summ = new resultsummarizer(result); assert.areequal(1, summ.resultcount); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -