Monday 12 September 2011

Sample JUnit Test Suite

Test Suite using JUnit....
 

Test1.java
------------------------------------------------------------
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.*;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class Test1 {

private Selenium selenium;
private SeleniumServer seleniumServer;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}

@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}

@Test
public void testText1() throws Exception {
selenium.open("URL");
//* Do the Operation

*/

}
}

/***********************
Test2.java
***************/

public class Test2 {

private Selenium selenium;
private SeleniumServer seleniumServer;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}

@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}

@Test
public void testText1() throws Exception {
selenium.open("URL");
//* Do the Operation

*/

}
}


/***********************

Finally The Test Suite

***************/

package com.Testscripts;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

public class TestSuite1 extends TestCase {

public static Test suite()
{
TestSuite nag = new TestSuite();

nag.addTestSuite( Test1.class);
nag.addTestSuite( Test2.class);
return nag;
}

public static void main(String arg[])
{
TestRunner.run(suite());

}
}
------------------------------------------------------------
Run the TestSuite.java script ...it will automatically run the tests(Test1 and Test2)

1 comment:

  1. Sir, please let me know if you conduct classroom trainings. I am intrested to learn selenium

    ReplyDelete