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