I. Introduction of the topic
The year and month are entered by the user, and then the calendar for that month is displayed in the console.
Second, the source of GitHub links .
Https://github.com/zhangxinn/test/blob/master/PrintCalendar
Third, the design of the module test cases, test results
First create a new project called junit_test, we write a Calculator class, and then unit test these functions.
Code
The second step is to introduce the JUnit4 Unit test package into this project: Right-click on the item, click "Properties",
In the pop-up Properties window, first select "Java Build Path" on the left, then select the "Libraries" tabon the right, then on the far right, click on the "ADD The Library"" button, as shown in:
Then select JUnit4 in the new pop-up dialog and click OK, as shownin theJUnit4 software package is included in our project.
The third step is to generate the JUnit test framework: Right-click the pop-up menu in Eclipse 's package Explorer and select JUnit test Case ". As shown in the following:
In the popup dialog box, make the appropriate selections as shown in:
After clicking "Next", the system will automatically list the methods contained in your class and choose the method you want to test.
The system then automatically generates a new class Printcalendartest, which contains some empty test cases. You only need to make these test cases slightly modified to use. The complete printcalendartest code is as follows:
Import static org.junit.assert.*;
Import Org.junit.Before;
Import Org.junit.Test;
public class Printcalendartest {
@Before
public void SetUp () throws Exception {
}
@Test
public void Testgetmonthname () {
Fail ("not yet implemented");
}
@Test
public void Testprintmonthbody () {
Fail ("not yet implemented");
}
@Test
public void Testgettotalnumberofdays () {
Fail ("not yet implemented");
}}
Fourth step, run the test code: After modifying the code as described above, we right-click on the Printcalendartest class and select "Run Asàjunit Test" to run our test as shown in:
The results of the operation are as follows:
The results show that "a total of 3 tests were performed, 0 of which were ignored and3 failed."
Iv. problems and solutions, experience.
There is a serious listen to the teacher in the classroom how to use Eclipse to JUnit4 module test, but one to the next class, alone, when the brain is blank, to all feel strange, But I caught the very common network in life, using the browser I found the solution, step by step study, completed the homework. At the same time, I understand that students should be good at using the resources and practice of the importance of the classroom, light on the basic knowledge, will only talk on paper, is unable to master the essence of knowledge, only through practice, can the real transformation of knowledge into their own, and then use the knowledge to learn more, to create the scientific value of knowledge, Make learning more meaningful.
Using Eclipse to test program modules with JUNIT4