Java-junit's Hello World

Source: Internet
Author: User

The basic configuration of JUnit 4 is described here:

<1> Build a Java Project project.

<2> build a package under the SRC directory, COM.SUN.JUNIT4, and write a little file under the package T.java

Package Com.sun.junit4;public class T {//test this method public int add (int x, int y) {return  x + y;}}

<3> build a package under the SRC directory, com.sun.test build a Ttest.java below

<4>ttest.java will automatically generate code

Package Com.sun.test;import static Org.junit.assert.*;import Org.junit.test;public class Bbest {@Testpublic void Testadd () {fail ("not yet implemented");}}

The Testadd () method Here is a test method for the T.java Add method, which modifies the code inside to

Package Com.sun.test;import static Org.junit.assert.*;import Org.junit.test;import Com.sun.junit4.t;public class TTest {@Testpublic void Testadd () {int z = new T (). Add (Ten); Assertequals (50,z);//system.out.println ("Test" + Z);}}

 <5> Click on Ttest.java to run with the JUnit test method, this window will appear, where the failures is the test fails, you can replace the correct result test can compare the difference

Java-junit's Hello World

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.