JUnit methods: Assertequals and Asserttrue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.