Assertequals and Asserttrue distinguish code blocks from running successful results assertequals error prompts after a failed run Asserttrue summary of errors after a failed run
assertequals and Asserttrue differences
the same: can determine whether two values are equal
Asserttrue If True, the success is run, and vice versa failure
Assertequals if the expected value is equal to the true value, run success and vice versa failure
The difference:
Assertequals run failure will have an error prompt, the expected value is xxx, and the actual value is XXX. Easily Adjustable
Asserttrue no error prompt code block
App.java
Package com.yubai.Test;
public class App
{public
String method () {
return This.getclass (). GetName ();
}
}
Apptest.java
Package com.yubai.Test;
Import static org.junit.assert.*;//must be static
import org.junit.Test;
public class Apptest {
app app = new app ();
@Test public
void Testbaseclass () {
asserttrue (App.method (). Equals ("com.yubai.Test.App"));
@Test public
void TestMethod () {
assertequals ("com.yubai.Test.App", App.method ());
}
}
Run Successful results
assertequals error message after a failed run
Org.junit.comparisonfailure:expected:<...ven. Testmaven_test. A[]> but Was:<...ven. Testmaven_test. a[pp]> asserttrue error message after a failed run
Summary
Both methods can be judged, generally recommended to use assertequals easy to debug