my teammates are 52 Wu Shu Ting, blog content is mainly white box black box test data analysis
We use simple arithmetic to test and package the program.
The main thing we do is
(1) Encapsulation: Encapsulation of the method to be used in the operation
There are three main files: Calculate (for storing operations to be used), calcutest (main Main method), test (testing)
Main methods in calculate: Cal (), input (), Judge judgment ()
The code is as follows: Calcutest (primary Main method)
PackageTest.src.src;ImportJava.util.Scanner; Public classCalcutest {StaticScanner sc =NewScanner (system.in); Static intA=0; Static intB=0; StaticString cc=NewString (); Public Static voidMain (string[] args) {Calculate C1=NewCalculate (); C1.input (); A=c1.a1; b=c1.b1; CC=c1.cc1; intTotal=C1. Cal (A,B,CC); System.out.println (The calculation results are: "+Total ); } }View Code
Calculate (storage operation to be used to get the method)
PackageTest.src.src;ImportJava.util.Scanner; Public classCalculate {StaticScanner sc =NewScanner (system.in); intA1=0; intB1=0; String CC1=NewString (); Static Public intCal (intAintb,string cc) {CC=judge (CC); intResult=0; if(Cc.equals ("+") ) Result=a+b; Else if(Cc.equals ("-") ) Result=a-b; Else if(Cc.equals ("*") ) Result=a*b; Else if(Cc.equals ("/")) Try{result=a/b; }Catch(Exception e)//exception handling of input values{System.out.println ("\ t divisor cannot be 0"); } ElseSystem.out.println ("\ t Please enter the correct operator!" Please re-execute the "); returnresult; } Public voidinput () {Try{System.out.println ("Operator is +,-, *,/"); System.out.println ("Please enter the first number:"); A1=Sc.nextint (); System.out.println ("Please enter a second number:"); B1=Sc.nextint (); System.out.println ("Please enter operator:"); CC1=Sc.next (); }Catch(Exception e) {System.out.println ("An exception occurred in the input value"); } } Static Publicstring judge (String cc2) {BooleanA=false; if(Cc2.equals ("+") | | cc2.equals ("-") | | cc2.equals ("*") | | Cc2.equals ("/")) a=true; while(a==false) {System.out.println ("\ t illegal operator"); System.out.println ("Please enter operator:"); CC2=Sc.next (); if(Cc2.equals ("+") | | cc2.equals ("-") | | cc2.equals ("*") | | Cc2.equals ("/")) a=true; } returnCC2; } }View Code
(2) test
A, the basic test of four operations
B, the division divisor can not be 0 of the test
C, logarithmic numerical specification for testing
D. Test for the correct input operator
PackageTest.src.src;Import Staticorg.junit.assert.*;Importorg.junit.Test; Public classTests {@Test Public voidTestadd ()//test addition basic functions { intresult=NewCalculate (). Cal (3,3, "+"); Assertequals (6, result); } @Test Public voidTestSub ()//Test subtraction Basic function { intresult=NewCalculate (). Cal (6,3, "-"); Assertequals (3, result); } @Test Public voidTestmuti ()//test multiplication Basic Functions { intresult=NewCalculate (). Cal (3,3, "*"); Assertequals (9, result); } @Test Public voidTestdivi ()//Test Division Basic Functions { intresult=NewCalculate (). Cal (3,3, "/"); Assertequals (1, result); } @Test Public voidTestdivizero ()//Test Division out of the book is not 0 basic functions{Calculate C1=NewCalculate (); C1. Cal (3, 0, "/"); } @Test Public voidTestilligal ()//{Calculate C1=NewCalculate (); C1.input (); } @Test Public voidTestcalstr ()//{Calculate C1=NewCalculate (); C1. Cal (3,5, "K"); }}View Code
Run results
Test start:
Test operator
Test all
Can test out the basic error-free program, there is a deeper error will be in the back of the update ~ ~ ~
Because the unit test here is not sure, start from the simple, but also dare not use their own procedures to test, will someday use my own program to test
Testing and Encapsulation 5.1