ant - How do i generate a junit report with fail -


i have junit testscript creates different , unique id. when finds existing id or wrong id want test script report via ant show failed following record passed rest of records correct.

                @test                 public void testcreatetrade() throws exception                 driver.findelement(by.id("vin")).clear();                 driver.findelement(by.id("vin")).sendkeys(vvin);                 string str = driver.getcurrenturl();                 if(str.contains("step1")) // existing id                 {                     driver.findelement(by.cssselector("body > div.bootbox.modal.in > div.modal-footer > a.btn.null")).click();                     break;                 }                 driver.findelement(by.id("mileage")).sendkeys(vmileage);                 driver.findelement(by.id("odometertype")).sendkeys(vkm);                 driver.findelement(by.id("passengers")).sendkeys(vpassengers);                 driver.findelement(by.id("exteriorcolor")).sendkeys(vexterior);                 driver.findelement(by.id("interiorcolor")).sendkeys(vinterior);                 driver.findelement(by.id("hasaccident")).sendkeys(vaccident);                 driver.findelement(by.id("dealersalesperson")).sendkeys(vsalesperson);                 driver.findelement(by.id("step3btn")).click();                 thread.sleep(1000);                 string str3 = driver.getcurrenturl();                 if(str3.contains("step2")) // loop wrong id                 {                     driver.findelement(by.linktext("create")).click();                     driver.findelement(by.xpath("html/body/div[7]/div[2]/a[1]")).click();                     //system.out.println("is wrong vin"+vvin);                     break;                 }                 driver.findelement(by.id("step4btn")).click();                 driver.findelement(by.id("windshieldcondition")).sendkeys(vwindshield);                 driver.findelement(by.id("tirecondition")).sendkeys(vtire);                 driver.findelement(by.id("accidentbrand3")).sendkeys(vacbrand);                 driver.findelement(by.id("confirmedparked")).click(); 

if want single test case continue running after "fails" , report exceptions @ end, use errorcollector.

@runwith(junit4.class) public class yourtestclass {   @rule public errorcollector errorcollector = new errorcollector();    @test public void yourtest() {     // ... (your setup)     (record record : expectedrecords) {       if (datasource.hasrecord(record.getid())) {         record fetchedrecord = datasource.getrecord(record.getid());         errorcollector.checkthat(record, matchesrecordvaluesof(record));       } else {         errorcollector.adderror(new illegalstateexception(""));       }     }   } } 

note, however, it's preferable test 1 thing per unit test. here may make sense, don't overuse errorcollector refactoring , splitting test makes more sense.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -