(a) Unit testing
(1) Three kinds of code
Pseudo code
Product Code
Test code
General testing:
Boundary test:
Test error condition
Correction Code:
(2) TDD (test driven devlopment, testing-driven development)
The general steps for TDD are as follows:
Clear the current functionality to be completed and record it as a test list
Quick completion of writing test cases for this feature
Test code compilation does not pass (no product code)
Write the Product Code
Test Pass
Refactor the code and ensure the test passes (refactoring the next lab session)
Cycle through the development of all functions
The coding rhythm of TDD is:
Add test code, JUnit appears red bar
Modify product code, JUnit appears green bar, Task complete
Self-test:
(ii) Object-oriented three elements
(1) Abstract
(2) encapsulation, inheritance and polymorphism
Implementations of inheritance and polymorphism:
(iv) Practice
1 use TDD to design the complex to implement the plural class.
Pseudo code
Product Code
Class Complex
{
Double Re,im;
Complex ()
{
this.re=0;
this.im=0;
}
Complex (Double re)
{
This.re=re;
this.im=0;
}
Complex (double re,double IM)
{
This.re=re;
This.im=im;
}
Complex Add (complex P1,complex p2)
{
Complex p=new complex (p1.re+p2.re,p1.im+p2.im);
return p;
}
Complex minus (complex p1,complex p2)
{
Complex p=new complex (p1.re-p2.re,p1.im-p2.im);
return p;
}
void print ()
{
System.out.println ("The value of the plural is:");
if (this.im!=0)
System.out.println (this.re+ "+" +this.im+ "I");
Else
System.out.println (this.re);
}
}
public class Song
{
public static void Main (string[] args)
{
Complex c=new complex ();
Complex c1=new complex (2,7);
Complex c2=new complex (5,2);
C1.print ();
C2.print ();
System.out.println ("The sum of these two complex numbers is:");
System.out.println ((C.add (C1,C2). re+ "+" +
C.add (c1, C2). im+ "I"). ToString ());
System.out.println ("The difference between these two complex numbers is:");
System.out.println ((C.minus (C1,C2). re+ "+" +
C.minus (c1, C2). im+ "I"). ToString ());
}
}
Test results
3. Statistics PSP (Personal software Process) time
Steps |
Take |
Demand analysis |
5% |
Design |
20% |
Code implementation |
60g |
Test |
30% |
Analysis Summary |
5% |
Four: summary
1. Experimental summary: The main content of this experiment is the code object-oriented three elements of the application, as well as the code design ideas and testing methods, through this week and last week's PSP time ratio can be seen, the proportion of design and testing increased, and the code to achieve the proportion of time decreased, which is closer to daily life of the basic software development Program Instead of practicing on a given topic in a book. Through the previous basic exercises have mastered the basic Java programming statement, will pay more attention to the practice of programming thinking in the future
2. Benefits of Unit Testing:
1. Help developers write code to improve quality and reduce bugs.
2. Improve the speed of feedback, reduce duplication of work, improve development efficiency.
3. Ensure that the last code modification does not break the functionality of the previous code.
4. Make the code easier to maintain.
Experiment two Java object-oriented programming