Packagecom.h1;Import Staticorg.junit.assert.*;ImportOrg.junit.Assert;ImportOrg.junit.Before;Importorg.junit.Test;ImportCom.h2.Core; Public classcoretest {@Test Public voidTestadd () {//addition intn = 3;//Number of Operations int[] Num1 = {1, 2, 3};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] No = {1, 1};//Operation PouteCore C =NewCore (); C.calcute (num1,op,no,n);//Operation 1+2+3 intR = (int) C.getresult (); System.out.println (R); Assertequals (6, R); } @Test Public voidTestjian () {//Subtraction intn = 3;//Number of Operations int[] Num1 = {1, 2, 3};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] No = {2, 2};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation intR = (int) C.getresult (); System.out.println (R); Assertequals (-4, R); } @Test Public voidTestmulti () {//multiplication intn = 3;//Number of Operations int[] Num1 = {2, 2, 3};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] No = {3, 3};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 2*2*3 intR = (int) C.getresult (); System.out.println (R); Assertequals (12, R); } @Test Public voidTestdiv () {//Division intn = 2;//Number of Operations int[] Num1 = {2, 2, 3};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] no = {4};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//operation 2/2 DoubleR =C.getresult (); System.out.println (R); Assertequals (1, r,100); } @Test (Expected= ArithmeticException.class) Public voidTestzero () {//divide by 0 . intn = 3;//Number of Operations int[] Num1 = {1, 0, 3};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] No = {4, 1};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 1/0+3} @Test Public voidTestnormal () {//Mixed Operations intn = 5;//Number of Operations int[] Num1 = {1, 2, 3, 4, 4};//Number of operands Char[] op = {', ' + ', '-', ' * ', '/'};//operator int[] No = {1, 3,2,4};//Operation PouteCore C =NewCore (); C.calcute (NUM1, OP, no, n);//Operation 1+2*3 intR = (int) C.getresult (); System.out.println (R); Assertequals (6, R); } }
Test Class
-this assignment is done with my partner Lin Juewen, and the detailed test code is here http://www.cnblogs.com/wzhz/
-(1) Black box test. This test is primarily to test the functionality and use of the code in terms of user perspective, as well as the presence of some external environment-related issues. such as:
-(2) white box test. Detailed examination of the procedural details of the software. The method is to put the test object
As an open box, it allows testers to design or select test Cases and test all the logical paths of the program, using the logical structure and related information inside the program. This is done by overwriting the path with conditional overrides. This is primarily a test of a module core with computational capabilities. (Because the computer screen is small, it only intercepts most of it.) Because this is the first time to do this test unit, so there are a lot of deficiencies, will gradually improve.
Exercise 5.1 Update--Arithmetic testing and encapsulation