dcsimg
dynamic junit, testing different things with one test file
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dominik_Dorfmeister
Posted On:   Monday, July 7, 2003 12:39 AM

is it possible to create a test file which tests something depending on its constructor, so you can have the same test file testing different and more things, or do you need an own test file for every testcase you want to do!?




thanks in advance for your answers!

Re: dynamic junit, testing different things with one test file

Posted By:   prashant_jani  
Posted On:   Friday, September 5, 2003 05:07 AM



Hi,
I guess u need to use junit extensions. Hope this helps u.

import junit.framework.*;
import junit.extensions.* ;

// helps u to run tests for specified no of times

public class SimpleRepeated extends RepeatedTest
{

public SimpleRepeated(Test test, int repeat){
super(test,repeat);
}

public static void main(String[] args)
{
SimpleRepeated sr = new SimpleRepeated(new SimpleSetup(),2);
TestResult tr = new TestResult();
sr.run(tr);
}
}

----------------------------------------------------

// allows to construct setup and tear down

public class SimpleSetup extends TestSetup
{
static int i = 1;

public SimpleSetup(Test test){
super(test);
}

public SimpleSetup(){
super(SimpleTest.suite());
}

protected void setUp() {
System.out.println("SS setup " + i);
i++;
// code to test the value of i and change the TestCase test variable values
}

protected void tearDown() {
System.out.println("SS tear down");
}
}

-----------------------------------------------

public class SimpleTest extends TestCase {
protected int fValue1;
protected int fValue2;

public SimpleTest(){
super();
}

public SimpleTest(String type){
super(type);
}

// get set methods for test variables fValue1, fValue2

public void testXXX() {
// code for the method
}
// other test methods

public static Test suite() {
TestSuite suite= new TestSuite();
return new TestSuite(SimpleTest.class);
}
}

i hope this provides some control on the values.
u can look for other junit extensions 'suiterunner-1.0beta6' (www.artima.com) which can serve your purpose.

hope this provided some help.

regards
Jani

Re: dynamic junit, testing different things with one test file

Posted By:   Dominik_Dorfmeister  
Posted On:   Tuesday, July 8, 2003 12:07 AM

yes that i already know, but i mean to do a testfile with parameters, given to my testfile by the constructor to get some flexibilty, e.g. test a string with the string he gets via the constructor.

Re: dynamic junit, testing different things with one test file

Posted By:   Jeanne_Boyarsky  
Posted On:   Monday, July 7, 2003 05:33 PM

You can have multiple test cases in the same file, but they all would get run.
About | Sitemap | Contact