In this step you will create a test class that will run tests on the control you just created. You can put tests in a separate source folder for better organization and so it's easier to exclude them later during packaging for production. Better yet, you can put the tests in a completely separate project, provided that the project dependencies are correctly configured. But, in this simple case, we will leave the control and test class in the same project.
In this section, you will:
To Create a New Source Folder and Package
Here, you'll create a new source folder to hold the test class.
In this step you will create the class that tests your control.
package sharedcontrols.test; import org.apache.beehive.controls.api.bean.Control; import org.apache.beehive.controls.test.junit.ControlTestCase; public class EmployeeControlTestCase extends ControlTestCase { @Control sharedcontrols.EmployeeControl employeeControl; /* * Test method for 'sharedcontrols.EmployeeControl.getManagerNames()' */ public void testGetManagerNames() { String[] mgrs = employeeControl.getManagerNames(); assertNotNull("Didn't find managers!", mgrs); assertTrue("Found wrong number of managers!", mgrs.length == 3); } }
(Notice that you were able to use the control simply by using the @Control field notation and didn't have to programmatically instantiate it yourself. That's the magic of ControlTestCase. By extending that class you inherit its setUp() and tearDown() methods that do the declarative wire-up for you.)
Related Topics