java - How can I use Assert in Unit Testing? -
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 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 http , https protocols")); if(assert.asserttrue(pageastext.contains("support http , https protocols"))){ system.out.println("true"); } else { system.out.println("false"); } system.out.println("test"); webclient.closeallwindows(); } }
why run in eclipse, returns "test"? how can print results asserts?
if(assert.asserttrue(pageastext.contains("support http , https protocols"))){ system.out.println("true"); } else { system.out.println("false"); }
i have error:
type mismatch: cannot convert void boolean
how can use if
assert
?
assert.asserttrue
void return. throws exception if input not true. useful in tests want crash indicate there problem.
looks in case want if(condition)
, not if(assert.asserttrue(condition))
. don't have use case assert.
Comments
Post a Comment