Software Test Learning notes: Getting Started with JUnit

Source: Internet
Author: User

The first time the software test was on the computer class, the project was tested for the first time using Juint.

Installation is the beginning of the work, Juint installation is relatively easy, just need to bring the required jar package into the project can

The first triangle code is as follows:

 PackageCom.tju.scs; Public classTriangle {intA, B, C;  PublicTriangle () {a= 0; b= 0; C= 0; }     PublicTriangle (intAintBintc) {        if(A >b) {inttemp =A; A=b; b=temp; }        if(A >c) {inttemp =A; A=C; C=temp; }        if(B >c) {inttemp =C; C=b; b=temp; }                 This. A =A;  This. B =b;  This. C =C; }    intTest () {intx = 0; if(A + b < C | | a <=0 | | b <= 0 | | c <= 0) x= 0; Else if(A = = b && b = =c) {x= 1; }        Else if(A = = B | | b = =c) {x= 2; }        Elsex= 3; returnx; }    intlegal () {if( This. Test ()! = 0)            return1; Else            return0; }    intIsoscelestriangle () {if( This. Test () = = 1 | | This. Test () = = 2)            return1; Else            return0; }    intEquilateraltriangle () {if( This. Test () = = 1)            return1; Else            return0; }    intNormaltriangle () {if( This. Test () = = 3)            return1; Else            return0; }}

The unit test code generated by JUnit is as follows

 PackageCom.tju.scs;Import Staticorg.junit.assert.*;ImportOrg.junit.Before;Importorg.junit.Test; Public classtriangletest {Triangle tr=NULL; @Before Public voidSetUp ()throwsException {intA = 0; intb = 0; intc = 0; TR=NewTriangle (A, B, c); } @Test Public voidTestlegal () {assertequals (0, Tr.legal ()); } @Test Public voidTestisoscelestriangle () {assertequals (0, Tr.isoscelestriangle ()); } @Test Public voidTestequilateraltriangle () {assertequals (0, Tr.equilateraltriangle ()); } @Test Public voidTestnormaltriangle () {assertequals (0, Tr.normaltriangle ()); }}

With a = 0, b = 0, c = 0 as three sides, the test code results are as follows:

That is, this triangle is illegal, non-isosceles, non-equilateral, non-ordinary triangles.

Software Test Learning notes: Getting Started with JUnit

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.