從我的JUnit測試中,我想調用此方法,但是它可以讓我調用它,但是它應該會導致錯誤,它會通過測試而不是失敗。從創建失敗的JUint測試中調用方法
public void handleErrors(String string, boolean b) {
System.out.println(string + ", " + b);
if(b == false){
collector.addError(new Throwable(string + ", " + b));
}
}
如果我通過這個測試中應該導致失敗,但它不會失敗。
@Test
public void test() throws InterruptedException {
handleErrors("Button was found", false);
}
爲什麼JUint沒有報告失敗?
編輯:
package com.selenium.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
import org.junit.rules.ErrorCollector;
import com.selenium.AbstractScreenTest;
public class test1 extends AbstractScreenTest{
@Rule
public ErrorCollector collector= new ErrorCollector();
@Before
public void initialize() {
createTest();
}
@Test
public void test() throws InterruptedException {
handleErrors("Button was found", false);
}
public void handleErrors(String string, boolean b) {
System.out.println(string + ", " + b);
if(b == false){
collector.addError(new Throwable(string + ", " + b));
}
}
@After
public void tearDown(){
closeTest();
}
}
爲什麼這會失敗?它不會拋出異常,測試不會斷言任何事情。 –
因爲我通過了錯誤,如果它是錯誤的,它會添加一個新的可拋出錯誤,並且它在JUint測試文件中有效,但不在這個單獨的類中。 – Colin747
請向我們展示可用的代碼。但是,當測試被寫入時,沒有東西會導致它失敗。如果拋出異常(技術上是可拋出的)或斷言失敗,並且在您的示例中都沒有發生,則測試將失敗。 –