Generating JUnit test cases for annotated-method interfaces

You can generate a new JUnit test case for an interface that declares annotated methods, or you can update an existing JUnit test case for such an interface.

About this task

You can generate a test method for each annotated method that is in the interface. The name of each test method is testindex_Name-of-annotated-method(), where index is the index of the method in the interface. For example, if getEmployee() is the third method that the interface declares, the name of the corresponding test method is test3_getEmployee().

If an annotated method takes parameters, the test method contains comments to indicate that one must assign a value to the parameters.

Finally, test methods contain no code for processing results.

Here is an example test method:
@Test
	public void test2_getEmployee() throws Exception {
		String empno = null;
		// TODO: empno = String value

		// Execute SQL statement
		Employee bean = data.getEmployee(empno);
}

Procedure

To generate a new JUnit test case or update an existing one:

  1. In the Package Explorer, right-click the source file in which the interface is defined and select pureQuery > Generate JUnit The Generate JUnit for Interface wizard opens.
  2. In the wizard, specify the name of the JUnit test case that you want to create.
    • To modify an existing JUnit test case, specify the name of that test case.
    • To generate a new JUnit test case, specify a name that is not already being used.

    You must also specify whether to include in the test case the JDBC URL and user ID for connecting to your data source, or to pass this URL, user ID, and password as parameters when you run the test case.

  3. Click Finish. If you are generating a new test case, it appears in the Package Explorer in the source folder and package that you specified in the wizard. If you are modifying an existing test case, you can specify whether you want to insert the new content into that test case or overwrite the test case.

Feedback