package htmlunit;
import org.junit.Assert;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class Test {
public static void main(String[] args) throws Exception {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());
final String pageAsXml = page.asXml();
Assert.assertTrue(pageAsXml.contains("<body class=\"composite\">"));
final String pageAsText = page.asText();
Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"));
if(Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"))){
System.out.println("true");
} else {
System.out.println("false");
}
System.out.println("test");
webClient.closeAllWindows();
}
}
왜 이클립스에서 실행하면 "테스트"만 반환됩니까? 어설 션에서 결과를 인쇄하려면 어떻게해야합니까?
if(Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"))){
System.out.println("true");
} else {
System.out.println("false");
}
그 오류가 있습니다.
유형 불일치 : void에서 부울로 변환 할 수 없습니다.
if
와 함께 어떻게 사용할 수 Assert
있습니까?
Assert.assertTrue
무효 반환입니다. 입력이 참이 아니면 예외가 발생합니다. 이것은 문제가 있음을 나타 내기 위해 충돌하려는 테스트에 유용합니다.
귀하의 경우에는 귀하가 원하는 if(condition)
것이 아닌 것처럼 보입니다 if(Assert.assertTrue(condition))
. 실제로 Assert에 대한 사용 사례가 없습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다