In the evening, I briefly talked with Xiao Bing about the method of using JUnit to test the filenet PE class. The advantage of using JUnit for testing is self-evident when using the main () method in the class. Although the necessity and superiority of lab and JUnit are not significant, it is worth exploring.
As a knowledge point, JUnit has already learned, and learning is a knowledge point. The knowledge point itself is dead. If it is not used flexibly, it will not take the initiative to help us solve the problem.
Testing the filenet operation class is a problem. I did not think about the involved knowledge points and tried to use the learned knowledge points. I did not sum up its usage when I learned the knowledge points and thought about its application scenarios, in short, knowledge points do not interact with actual problems, and the opportunity for integration is lost. The realm of integration is the knowledge network proposed by Mr. Mi. The simple analysis is to discard the learning method in the process of police learning. In the figure, p is the knowledge point, Q is the actual problem, and the two arrows on PQ are the mutual action. Think about the situation in which PQ and their interactions are constantly increasing?
Next we will briefly review the use of JUnit.
1.
Introduce JUnit. jar,: http://www.junit.org/
2.
The test class must inherit the testcase class. The method has no return value and no parameters.
3.
One specification:
1) The test class name is followed by the name of the tested class,
2) The method name in the test class adopts the method tested by test +.
4.
Asserted: There is a green progress bar for unit testing, but it is still necessary to check whether it can pass directly. If we want to let our test cases run automatically when we get the job back home, and verify the correctness, we need to use JUnit's assertions. Assertions provide a comparison method between the expected value and the actual value.
5. The setup () method can handle the tasks to be done before the test method is executed, such as logging on to PE, and teardown () can handle the tasks to be done after the test method is executed, such as exiting PE.
Code example:
Original class: public class rosterqueryedu
Method to be tested in this class: Public Boolean rosterqueryedu (vwsession)
Test code (compare the use of assertions and non-assertions in the test method ):
/**
*
Function:
*
Author: Chen Weidong
*
Data time: Jun 30,201 1 10:51:56
*/
Package com.ibm.filenet.edu;
Import filenet. VW. API. vwsession;
Import JUnit. Framework. testcase;
Public class rosterqueryedutest extends
Testcase {
Rosterqueryedu
Myinstance = NULL;
Vwsession
Vwsession = NULL;
Protected
Void setup () throws exception {
// Instantite
Myinstance = new
Rosterqueryedu ();
// Vwsession
Vwsession = myinstance. Logon ("Administrator ",
"Filenet ");
}
Protected
Void teardown () throws exception {
Myinstance. pelogoffedu (vwsession );
}
Public
Void testrosterqueryedu (){
Boolean
Actual = myinstance. rosterqueryedu (vwsession );
// JUnit
Assert
This. assertequals (true,
Actual );
// If
We don't use JUnit assert, then we shoshould to see the output result
System. Out. Print ("
Result is: "+ actual );
}
}