Practice Two Personal Practice
School Number: 201303014010 name: Zhang Ping Ping class: ITCSC (Higher vocational) 13-1
I. Introduction of the topic
This practice is to create a subtraction simple small program, the main use of subtraction four methods to achieve simple digital computing.
second, the source of GitHub links :
https://github.com/elinesping/project2/blob/master/ Zhang Ping Ping -201303014010- Department of Higher Education 13-1- Practice two person Project code
Third, the design of the module test cases, test results
Module test Case Code:
Import static org.junit.assert.*;
Import Org.junit.Before;
Import Org.junit.Test;
public class Calculatortest {
private static Calculator Calculator = new Calculator ();
@Before
public void SetUp () throws Exception {
Calculator.clear ();
}
/* We would like to test the "addition" function is correct, in the test method called several times the Add function, the initial value is 0, plus 2, plus 3,
* We expect the result should be 5, the actual result is also 5, stating that the Add method is correct, the contrary means he is wrong.
@Test
public void Testadd () {
Calculator.add (2);
Calculator.add (3);
Assertequals (5, Calculator.getresult ());
}
/*assertequals (5, Calculator.getresult ());
* Just to determine if the expected results and actual results are equal, the first parameter fills in the expectation, the second parameter fills in the actual result,
* That is, the results obtained by calculation. */
@Test
public void Testsubstract () {
Calculator.add (10);
Calculator.substract (2);
Assertequals (8, Calculator.getresult ());
}
@Test
public void testmultiply () {
Calculator.add (10);
Calculator.multiply (2);
Assertequals (Calculator.getresult ());
}
public void Testdivide () {
Calculator.add (10);
Calculator.divide (2);
Assertequals (5, Calculator.getresult ());
}
}
Test results:
Test Case Structure diagram:
Iv. problems and solutions, experience
In this practice, I found a lot of errors when using the JUNIT4 to check the program, after the establishment of the test file, but also need to add the test code, and I also understand that to ensure the accuracy of the program, more tests should be conducted several times.
To solve this problem, to edit the test code, fail("not yet implemented"), change to calculator. Add (10); calculator. substract (2); assertequals (8, calculator. GetResult ()); So the problem is solved.
Through this test I learned junit4, and better review the previous Java knowledge, and learned how to use the module test cases, but also learned how to use the blog and GitHub to better learn the current knowledge. Through this practice I found that in fact, my Java is not too skilled, need to be strengthened.
Zhang Ping High School 13-1 201303014010 practice two person project