I have the following ant target:
<path id="test-classpath">
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<pathelement path="bin/release" />
</path>
<target name="run-test">
<junit printsummary="yes" haltonfailure="yes" fork="true">
<formatter type="failure"/>
<test name="someNamespace.someTest" />
<classpath refid="test-classpath" />
</junit>
</target>
When I try to run it from the command-line, I am getting the following output:
>ant run-test
Buildfile: ...\build.xml
[echo] 2016-03-30 20:29:29
run-test:
[junit] Exception in thread "main" java.lang.reflect.InvocationTargetException
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:343)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:257)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.transferFormatters(JUnitTestRunner.java:1085)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1180)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1033)
[junit] Caused by: java.lang.reflect.InvocationTargetException
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at java.lang.reflect.Method.invoke(Method.java:498)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:337)
[junit] ... 4 more
[junit] Caused by: java.lang.NullPointerException
[junit] at org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder.setProject(FailureRecorder.java:153)
[junit] ... 9 more
BUILD FAILED
...\build.xml:171: Using loader AntClassLoader[
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-launcher.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-junit.jar;
C:\Program Files (x86)\apache-ant-1.9.6\lib\ant-junit4.jar;
...\lib\commons-math3-3.5.jar;
...\lib\hamcrest-core-1.3.jar;
...\lib\junit-4.11.jar;
...\lib\log4j-api-2.5.jar;
...\lib\log4j-core-2.5.jar;
...\bin\release] on class org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder:
java.lang.NoClassDefFoundError: junit/framework/TestListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1407)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1085)
at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:287)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1854)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmCrash(JUnitTask.java:1818)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1295)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:1024)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:2105)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:832)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 51 more
Total time: 3 seconds
The test runs successfully within Eclipse Mars (4.5.2). Does anyone know why this would be happening, and how I can get my JUnit test to run through ant? I am using JUnit 4.11, and have tried ant v1.9.3 and v1.9.6 (the above output was generated from ant v1.9.6).
EDIT
I also tested using ant v1.8.4, per the recommendations in the comments, but that doesn't have any effect on the resulting crash (other than the version numbers of the jar files).
According to this question - Class not found with Ant, Ivy and JUnit - error in build.xml? - there is a bug in ant 1.9+ and you should try ant 1.8.4.
I finally figured out what the problem was. My JUnit task classpath was incorrect, as I forgot to include the location of my test suite class. Once I corrected the classpath, everything worked as expected. Still, I feel that this is a bug that should be addressed by either the Ant or JUnit teams. A message such as, "Class XXX could not be loaded" would have been much more helpful.
Related
I have a simple HelloWorld type Worklight application, with no adapters and just a 'common' environment. And I am trying to build the application through the build-app target supplied in the worklight-ant.jar file. This target fails with the following stack trace. Any ideas on why this might be happening?
StackTrace from command line
Buildfile: /Users/jai/Dev/Workspaces/worklight-2014/EFMobile/build.xml
init:
[echo] Loading ANT Tool
build-app:
[echo] Building app at /Users/jai/Dev/Workspaces/worklight-2014/EFMobile/apps/HelloEF
[echo] Worklight Ant Task version 6.1.0.00.20131123-2150
BUILD FAILED
/Users/jai/Dev/Workspaces/worklight-2014/EFMobile/build.xml:26: java.lang.ExceptionInInitializerError
at com.worklight.builder.environment.EnvironmentBuilderFactory.get(EnvironmentBuilderFactory.java:70)
at com.worklight.builder.ApplicationBuilder.buildEnvironment(ApplicationBuilder.java:268)
at com.worklight.builder.ApplicationBuilder.buildEnvironments(ApplicationBuilder.java:230)
at com.worklight.builder.ApplicationBuilder.build(ApplicationBuilder.java:119)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:112)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.RuntimeException: Failed creating resourcesRootFolder
at com.worklight.builder.environment.EnvironmentBuilder.initResourceFolder(EnvironmentBuilder.java:199)
at com.worklight.builder.environment.EnvironmentBuilder.<clinit>(EnvironmentBuilder.java:192)
... 22 more
Caused by: java.io.IOException: Resource not found: jslibexpanded.zip.MD5
at com.worklight.builder.util.BuilderUtils.unzipResourceIfRequired(BuilderUtils.java:723)
at com.worklight.builder.util.BuilderUtils.initResourcesFolder(BuilderUtils.java:704)
at com.worklight.builder.environment.EnvironmentBuilder.initResourceFolder(EnvironmentBuilder.java:197)
... 23 more
Total time: 1 second
may be your ant is older than the prerequisite version ?
http://publib.boulder.ibm.com/infocenter/prodguid/v1r0/clarity-reports/report/html/softwareReqsForProduct?deliverableId=66C745D01E8711E28ACF6F870925FE36&osPlatform=Linux#!
regards
I am trying to run a basic REST Web Service Test calling a Soap UI project from JUnit in ANT.
Everything compiles correctly and runs, however when I try to run a test that uses an external data file I get the error:
Unable to obtain resource from C:\soapTest\atmTest3.csv:
java.util.zip.ZipException: error in opening zip file
[junit] Unable to obtain resource from C:\soapTest\atmTest3.csv:
I have already searched and seen others who have had the problem with classes and tried to only include what I believe I need. This is how I include my data file in my build.xml
<path id ="test.input.dir" >
<pathelement path="C:\soapTest\atmTest3.csv" />
</path>
<path id="classpath.junittest">
<path refid="test.input.dir" />
<path refid="jars.dir" />
</path>
My JUNIT method is very basic
public void testRunner() throws Exception
{
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile("C:/soapTest/ATM-Locator-soapui-project.xml");
runner.run();
}
Has anyone had success using an external datasource file and running in JUNIT?
Are there alternatives?
------------------ ANT Output below -------------------
Building in workspace C:\JENKINS_PROJECTS\workspace\JUNIT_Test
[JUNIT_Test] $ cmd.exe /C '"C:\apache-ant-1.9.3\bin\ant.bat -D-Verbose="" -D-Debug="" && exit %%ERRORLEVEL%%"'
Buildfile: C:\JENKINS_PROJECTS\workspace\JUNIT_Test\build.xml
[echo] Apache Ant version is Apache Ant(TM) version 1.9.3 compiled on December 23 2013
[echo] Apache basedir is C:\JENKINS_PROJECTS\workspace\JUNIT_Test
compile:
[javac] Compiling 2 source files to C:\JENKINS_PROJECTS\workspace\JUNIT_Test\classes
compile-test:
[javac] Compiling 6 source files to C:\JENKINS_PROJECTS\workspace\JUNIT_Test\classes
test:
[junit] Running com.JUnit.AllTests
[junit] Testsuite: com.JUnit.AllTests
Unable to obtain resource from C:\soapTest\atmTest3.csv: java.util.zip.ZipException: error in opening zip file
[junit] Unable to obtain resource from C:\soapTest\atmTest3.csv:
[junit] java.util.zip.ZipException: error in opening zip file
[junit] at java.util.zip.ZipFile.open(Native Method)
[junit] at java.util.zip.ZipFile.<init>(Unknown Source)
[junit] at java.util.jar.JarFile.<init>(Unknown Source)
[junit] at java.util.jar.JarFile.<init>(Unknown Source)
[junit] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1006)
[junit] at org.apache.tools.ant.AntClassLoader.getResource(AntClassLoader.java:887)
[junit] at org.apache.log4j.helpers.Loader.getResource(Loader.java:96)
[junit] at org.apache.log4j.LogManager.<clinit>(LogManager.java:103)
[junit] at org.apache.log4j.Logger.getLogger(Logger.java:117)
[junit] at com.eviware.soapui.SoapUI.<clinit>(SoapUI.java:135)
[junit] at com.eviware.soapui.tools.SoapUITestCaseRunner.<clinit>(SoapUITestCaseRunner.java:79)
[junit] at com.util.ParameterATM_Test.testRunner(Unknown Source)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[junit] at java.lang.reflect.Method.invoke(Unknown Source)
[junit] at junit.framework.TestCase.runTest(TestCase.java:168)
[junit] at junit.framework.TestCase.runBare(TestCase.java:134)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:110)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:128)
[junit] at junit.framework.TestResult.run(TestResult.java:113)
[junit] at junit.framework.TestCase.run(TestCase.java:124)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:243)
[junit] at junit.framework.TestSuite.run(TestSuite.java:238)
[junit] at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
[junit] at org.junit.runners.Suite.runChild(Suite.java:128)
[junit] at org.junit.runners.Suite.runChild(Suite.java:24)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:532)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1425)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:852)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1904)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:804)
[junit] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
[junit] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[junit] at java.lang.reflect.Method.invoke(Unknown Source)
[junit] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[junit] at org.apache.tools.ant.Task.perform(Task.java:348)
[junit] at org.apache.tools.ant.Target.execute(Target.java:435)
[junit] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[junit] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[junit] at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[junit] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[junit] at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[junit] at org.apache.tools.ant.Main.runBuild(Main.java:851)
[junit] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[junit] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[junit] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
I tried to execute below mentioned ant mail task, I'm getting error message: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage.
I have created environment variable for ant.
Also placed mail.jar, activation jar & ant-javamail jar in lib folder as well as in eclipse -> preferences -> Global Entries. Anything else required for executing ant mail task? Please suggest.
<target description="Generates and send TestNG test reports" name="send-report">
<mail mailhost="smtp.sears.com" mailport="25" user="kmart\vlakshm" password="AK230211$$" ssl="true" subject="Test build">
<from address="vijayalakshmi.lakshmanan#searshc.com"></from>
<replyto address="vijayalakshmi.lakshmanan#searshc.com"></replyto>
<to address="vijayalakshmi.lakshmanan#searshc.com"></to>
<message>Please find the attached report for Sears International smoke test results.</message>
<attachments>
<fileset dir="C:\\Documents and Settings\\vlakshm\\workspace\\INTL_REG\\test-output\\emailable-report.html">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
In command prompt,executed below mentioned command
ant send-report
Getting below mentioned exception
build.xml:70: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:
452)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
add mail.jar and activation.jar in ANT_HOME/lib or use both jar form your project/lib
I have defined an Ant target containing in-memory HSQLDB:
<target name="create.tables" depends="-prepare.test">
<property name="db.connection.url" value="jdbc:hsqldb:mem:adb"/>
<property name="db.driver" value="org.hsqldb.jdbcDriver"/>
<property name="db.username" value="a"/>
<property name="db.password" value="a"/>
<echo>Creating tables using: ${db.driver} ${db.connection.url} ${product.mysql-connector.jar}</echo>
<sql driver="${db.driver}"
url="${db.connection.url}"
userid="${db.username}"
password="${db.password}"
onerror="stop"
src="/create-schema.sql">
<classpath refid="test.classpath" />
</sql>
</target>
The prepare.test only contains basic things such as fileset etc.
When I print the SQL inserts everything is OK. But how can I access the in-memory HSQLDB from a JUnit testcase?
I tried:
Class.forName("org.hsqldb.jdbcDriver");
connection = DriverManager.getConnection("jdbc:hsqldb:mem:adb",
"a", "a");
but there was only an empty database. Is it possible to use HSQLDB with the insert statements from the Ant target in JUnit testcases?
The exception in the junit test is as follows. The table exists because it is created in the ant task:
[junit] java.lang.Exception: user lacks privilege or object not found: MYTABLE
[junit] at com.inmemorytests.InMemoryTest.testSomething(InMemoryTest.java:116)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at java.lang.reflect.Method.invoke(Method.java:601)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
[junit] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
This is your connection URL in Ant:
<property name="db.connection.url" value="jdbc:hsqldb:mem:adb"/>
You must use the same URL and the same username and password for a connection:
connection = DriverManager.getConnection("jdbc:hsqldb:mem:adb", "a", "a");
Update: When using a memory database, the Ant target and the JUnit tests must run in the same JVM. If you are running the two in separate JVM's, start an HSQLDB server before the tests and connect to this server from each test. The server connection URL's are different and described in the HSQLDB Guide.
Below two stacks from the initial JVM and forked JVM seems saying the test code executed twice instead of only one time. I wonder why it is not only executed in the forked one.
JUnit test config: fork=true, forkmode=perTest
at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3099)
at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:164)
at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:369)
at oracle.security.jps.service.policystore.PolicyStoreTestCaseBase.<init>(PolicyStoreTestCaseBase.java:39)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.<init>(JpsJavaPolicyPreTestCase.java:145)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at junit.framework.TestSuite.createTest(TestSuite.java:65)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
at junit.framework.TestSuite.<init>(TestSuite.java:146)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.suite(JpsJavaPolicyPreTestCase.java:603)
at devtest.JpsUnitPreTestSuite.suite(JpsUnitPreTestSuite.java:66)
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:597)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.createTestSuite(JUnitTestRunner.java:929)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.createTestSuite(TLJUnitTestRunner.java:217)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.run(JUnitTestRunner.java:366)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.run(TLJUnitTestRunner.java:111)
at org.testlogic.testrunner.ant.junit4.JUnitTask.runTestInVM(JUnitTask.java:1319)
at org.testlogic.testrunner.ant.junit4.TLJUnitTask.runInitMode(TLJUnitTask.java:327)
at org.testlogic.testrunner.ant.junit4.TLJUnitTask.run(TLJUnitTask.java:120)
at org.testlogic.impl.ant.JITInitModeListener.runTestTaskInInitMode(JITInitModeListener.java:91)
at org.testlogic.impl.ant.JITInitModeListener.taskStarted(JITInitModeListener.java:121)
at org.apache.tools.ant.Project.fireTaskStarted(Project.java:2131)
at org.apache.tools.ant.Task.perform(Task.java:345)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1307)
at org.testlogic.impl.ant.AntTaskUtils.simulateAntCall(AntTaskUtils.java:273)
at org.testlogic.impl.ant.executionPlan.model.CommandRunnable.runCommand(CommandRunnable.java:178)
at org.testlogic.impl.ant.executionPlan.model.CommandRunnable.run(CommandRunnable.java:105)
at java.lang.Thread.run(Thread.java:662)
and
at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3099)
at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:164)
at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:369)
at oracle.security.jps.service.policystore.PolicyStoreTestCaseBase.<init>(PolicyStoreTestCaseBase.java:39)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.<init>(JpsJavaPolicyPreTestCase.java:145)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at junit.framework.TestSuite.createTest(TestSuite.java:65)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
at junit.framework.TestSuite.<init>(TestSuite.java:146)
at oracle.security.jps.service.policystore.JpsJavaPolicyPreTestCase.suite(JpsJavaPolicyPreTestCase.java:603)
at devtest.JpsUnitPreTestSuite.suite(JpsUnitPreTestSuite.java:66)
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:597)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.createTestSuite(JUnitTestRunner.java:929)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.createTestSuite(TLJUnitTestRunner.java:217)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.run(JUnitTestRunner.java:366)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.run(TLJUnitTestRunner.java:111)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.launch(JUnitTestRunner.java:869)
at org.testlogic.testrunner.ant.junit4.JUnitTestRunner.main(JUnitTestRunner.java:714)
at org.testlogic.testrunner.ant.junit4.TLJUnitTestRunner.main(TLJUnitTestRunner.java:209)
JUnit section in build.xml
<!-- Run in its own JVM. todir="${test.results.dir}" -->
<test todir="${test.results.dir}" name="devtest.JpsUnitPreTestSuite" unless="jps.testcase"/>
<!-- Followed by these tests. -->
<test todir="${test.results.dir}" name="devtest.JpsUnitTestSuite" unless="jps.testcase"/>
<!-- JVM system properties -->
<sysproperty key="src.home" value="${env.ADE_VIEW_ROOT}"/>
<sysproperty key="ant.home" value="${ant.home}"/>
...