Web site template - CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT
CHAPTER 5 PERFORMANCE THROUGH THE APPLICATION DEVELOPMENT LIFE CYCLE In addition, JUnit offers a fail() method that you can call anywhere in your test case to immediately mark a test as failing. JUnit tests are executed by one of the TestRunner instances (there is one for command-line execution and one for a GUI execution), and each version implements the following steps: 1. It opens your TestCase class instance. 2. It uses reflection to discover all methods that start with test . 3. It repeatedly calls setUp(), executes the test method, and calls teardown(). As an example, I have a set of classes that model data metrics. A metric contains a set of data points, where each data point represents an individual sample, such as the size of the heap at a given time. I purposely do not list the code for the metric or data point classes; rather, I list the JUnit tests. Recall that according to one of the tenets of Extreme Programming, we write test cases before writing code. Listing 5-1 shows the test case for the Metric class, and Listing 5-2 shows the test case for the DataPoint class. Listing 5-1. DataPointTest.java package com.javasrc.metric; import junit.framework.TestCase; import java.util.*; /** * Tests the core functionality of a DataPoint */ public class DataPointTest extends TestCase { /** * Maintains our reference DataPoint */ private DataPoint dp; /** * Create a DataPoint for use in this test */ protected void setUp() { dp = new DataPoint( new Date(), 5.0, 1.0, 10.0 ); }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services