Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant 如何生成带有fail的junit报告_Ant_Junit_Selenium Webdriver_Junit3_Junit Runner - Fatal编程技术网

Ant 如何生成带有fail的junit报告

Ant 如何生成带有fail的junit报告,ant,junit,selenium-webdriver,junit3,junit-runner,Ant,Junit,Selenium Webdriver,Junit3,Junit Runner,我有一个junit testscript,它创建了不同的唯一ID。因此,当它发现一个现有ID或一个错误ID时,我希望通过ANT的测试脚本报告显示它对以下记录失败,但对其余正确的记录传递 @Test public void testCreateTrade() throws Exception driver.findElement(By.id("VIN")).clear();

我有一个junit testscript,它创建了不同的唯一ID。因此,当它发现一个现有ID或一个错误ID时,我希望通过ANT的测试脚本报告显示它对以下记录失败,但对其余正确的记录传递

                @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")) // for 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 for 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 a 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();

如果您希望单个测试用例在“失败”后继续运行,然后在最后报告其异常,请使用


然而,请注意,每次单元测试只测试一件事情总是更可取的。在这里它可能有意义,但不要过度使用ErrorCollector,因为重构和拆分测试更有意义。

谢谢@Jeff Bowman:-我分离了我的测试用例。我对junit是新手。现在我正在使用Try-Catch块。因此,当我得到一个NoTouchElementException时,我需要使我的测试用例失败。简言之,在catch块中捕获的任何错误都应该将测试脚本设置为失败。现在它在ant生成的报告中将其设置为Error@测试(预期为NosuchElementFoundException)。这行得通。测试脚本是一个肯定的测试脚本,但是它得到了一个例外。如果我想让测试脚本失败,那么当我运行Build.xml文件时,它会作为错误出现删除预期的
;只有当异常指示测试正在工作时,您才需要它。相反,请尝试{/*…*/}catch(NSEE-NSEE){fail();}。也就是说,如果你有另一个具体的问题,请分别提问。StackOverflow旨在成为一个包含清晰问题和全面答案的存储库,因此,如果你已经克服了一个障碍,但仍然有问题,那么实际上最好单独问一个问题。祝你好运
@RunWith(JUnit4.class) public class YourTestClass {
  @Rule public ErrorCollector errorCollector = new ErrorCollector();

  @Test public void yourTest() {
    // ... (your setup)
    for (Record record : expectedRecords) {
      if (dataSource.hasRecord(record.getId())) {
        Record fetchedRecord = dataSource.getRecord(record.getId());
        errorCollector.checkThat(record, matchesRecordValuesOf(record));
      } else {
        errorCollector.addError(new IllegalStateException(""));
      }
    }
  }
}