You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Ian Huynh <ia...@hubspan.com> on 2003/12/16 02:27:02 UTC
unable to convert testcases that run OK in ServletTestRunner to run via ant task ?
I apologize in advance if this question has been asked before but
I've fought with <cactus> and ant for the last couple of days and can't get it to work.
Env:
----
JBoss 3.2.1 , Ant 1.5.3 Cactus 1.5 JUnit 3.8.1
BackGround
------------
1. JBoss has a customized run.bat file so I AM using the generic <containerset> which does nothing in the
start target and I manually start JBoss
2. I need to test my test cases inside the container b/c a number of the classes tested
rely on resources that are initialized by a servlet that is loaded on startup, so
running pure JUnit doesn't work.
3. my JUnit test class below works fine if I execute it using a browser and
browse to http://localhost:7000/test/ServletTestRunner?suite=com.acme.MyTestCase001
but if runing in <cactus> ant task, it errored out in the last line of code below
Seems like it's running out side of the container
public class MyTestCase001 extends TestCase
{
// -- basic stub --
public MyTestCase001 (String strName) { super (strName); }
public static Test suite() {
return new TestSuite(MyTestCase001.class);
}
public static void main(String[] theArgs) {
junit.textui.TestRunner.run(suite());
}
// -- end of basic stub --
public void test001() throws Exception {
// get the settings that was initialized by the Servlet
Throwable t = new Throwable();
t.printStackTrace();
//// fails here ////
Settings = SettingFactory.getSettings(); <-- // fails here b/c SettingFactory was not initialized
}
}
when running with ant -verbose i am getting this
[cactus] Adding Cactus server system property [cactus.cactus.contextURL] with value [null]
[cactus] -----------------------------------------------------------------
[cactus] Running tests against HubspanJBossContainer
[cactus] -----------------------------------------------------------------
[cactus] Starting up container
[cactus] Container responding to HTTP requests as null
... [cactus] , java.vm.specification.vendor=Sun .. (more stuff deleted)
... cactus.contextURL=http://localhost:7000/test, ...
and the throwable stack trace shows that Cactus calls ant to run (but it seems to run outside of the container)
at com.acme.MyTestCase001.test001(MyTestCase001 .java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:848)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:556)
at org.apache.cactus.integration.ant.CactusTask.executeInContainer(CactusTask.java:465)
at org.apache.cactus.integration.ant.CactusTask.execute(CactusTask.java:229)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.tools.ant.Target.execute(Target.java:309)
at org.apache.tools.ant.Target.performTasks(Target.java:336)
at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
at org.apache.tools.ant.Main.runBuild(Main.java:609)
at org.apache.tools.ant.Main.start(Main.java:196)
at org.apache.tools.ant.Main.main(Main.java:235)