Posted By:
Jennifer_Thompson
Posted On:
Monday, November 4, 2002 07:22 PM
Hi, I have two junit classes. One is TestInterface.java and the other is TestInterfaceDecorator.java. In TestInterface.java, I have tests to test a file ServiceBureau.java which is supposed to respond correctly to the messages it is sent. In TestInterface.java, I want to set up a log file and other variables ONCE only for all my tests. For this I have discovered I need another JUnit file, a decorator which I have called TestInterfaceDecorator.java So my question is, in TestInterfaceDecorator.java, how do I access TestInterface.java 's variables eg the log file? Where should the log file and other variables be defined and how can TestInterface and TestInterfaceDecorat
More>>
Hi,
I have two junit classes. One is TestInterface.java and the other is TestInterfaceDecorator.java.
In TestInterface.java, I have tests to test a file ServiceBureau.java which is supposed to respond correctly to the messages it is sent.
In TestInterface.java, I want to set up a log file and
other variables ONCE only for all my tests. For this I have discovered I need another JUnit file, a decorator which I have called TestInterfaceDecorator.java
So my question is, in TestInterfaceDecorator.java, how do I access TestInterface.java 's variables eg the log file? Where should the log file and other variables be defined and how can TestInterface and TestInterfaceDecorator have access to them?
I thought of something like this.. but it didn't work because of the cast from TestInterface to Test...
package testTool;
import java.io.*;
import java.util.ResourceBundle;
import junit.framework.*;
import junit.extensions.*;
public class TestInterfaceDecorator extends TestSetup {
public TestInterface testInterface;
public TestInterfaceDecorator(Test test) {
super(test);
// This is the line that doesn't compile
testInterface = test;
}
public void setUp() {
//User values is a resource bundle
testInterface.userValues = ResourceBundle.getBundle("testTool.userInput");
testInterface.commandRate = (new Integer(userValues.getString("commandRate"))).intValue();
testInterface.loggingRequired = (new Boolean(userValues.getString("loggingRequired"))).booleanValue();
testInterface.logFileLocation = userValues.getString("logFileLocation");
testInterface.ipSDP = userValues.getString("ipSDP");
testInterface.portSDP = userValues.getString("portSDP");
if(testInterface.loggingRequired) {
try {
log = new PrintStream(new FileOutputStream(testInterface.logFileLocation));
} catch (Exception e) {}
}
try {
humanTest = new PrintStream(new FileOutputStream(testInterface.HumanTestFileLocation));
} catch(Exception e) {}
}
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TestInterfaceDecorator(TestInterface.suite()));
return suite;
}
public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
}
Thanks for your help,
Jen
<<Less