Web hosting comparison - Creating a Test Suite All generated test methods
Creating a Test Suite All generated test methods start with the string test. JUnit recognizes such method names and executes them when running a test. Since the wizard has already generated the method stubs, you need only add the code inside the method body. If you need to initialize variables or other resources, you do this in the setUp() method. See Listing 6.1. import junit.framework.TestCase; import com.bdaum.dukeSpeaks.Player; public class PlayerTest extends TestCase { Player player; /** * Constructor for TestCase1. * @param arg0 */ public PlayerTest(String arg0) { super(arg0); } /** * Initialize the player */ protected void setUp() throws Exception { super.setUp(); player = new Player(”Animated FreeTTS Player”); } final public void testGetWidth() { assertTrue(”width != 600: “+player.getWidth(), player.getWidth() == 600); } final public void testGetHeight() { assertTrue(”height != 500: “+player.getHeight(), player.getHeight() == 500); } /** * Dispose of everything */ protected void tearDown() throws Exception { super.tearDown(); player = null; } } Listing 6.1 Here, two tests (testWidth() and testHeight()) are implemented. In these tests the JUnit assertTrue() method is used to test a condition and throw an exception if the condition is not met. Both methods use the player variable that was initialized in the setUp() method. JUnit calls this 122 Chapter 6
We strive to offer the highest quality service while maintaining a cheap and discount price structure. For your company, ecommerce, or personal web hosting needs, we offer the best solution.Trust us and please check quality web hosting services.