I am trying to run all the tests (all of them extend FlatSpec) in a jar using the ScalaTest Runner, but get a message for VerifyError. However, I am able to individually run the tests.
The jar was compiled using sbt test:assembly. I am trying to run the tests in another environment where sbt is not available. The tests are available in the jar in com/tfs/test path, as shown in the output below:
samik#samik-lap:~/git/proj$ jar tf test-2018.2.jar | grep MyTest
com/tfs/test/MyTest$$anonfun$1$$anonfun$apply$mcV$sp$1.class
com/tfs/test/MyTest$$anonfun$4.class
com/tfs/test/MyTest$$anonfun$5.class
com/tfs/test/MyTest$$typecreator4$1.class
com/tfs/test/MyTest$$typecreator5$1.class
com/tfs/test/MyTest$$typecreator9$1.class
com/tfs/test/MyTest.class
The following command runs the specific test just fine:
samik#samik-lap:~/git/proj$ scala -J-Xmx2g -cp "scalatest_2.11-3.0.5.jar:scalactic_2.11-3.0.5.jar:test-2018.2.jar" org.scalatest.run com.tfs.test.MyTest
0 [ScalaTest-main] INFO com.tfs.test.MyTest - Starting MyTest test application
Start Time: 0 sec
...
However, when I use Runner to run all the tests (there are ~7 similar tests in the jar available at the same path), it doesn't work.
samik#samik-lap:~/git/proj$ scala -J-Xmx2g -cp "scalatest_2.11-3.0.5.jar:scalactic_2.11-3.0.5.jar" org.scalatest.tools.Runner -o -R test-2018.2.jar
Discovery starting.
*** RUN ABORTED ***
java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
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)
How do I get all the tests to run through Runner? How do I get to know what is happening inside and where the issue is? Thanks for any pointer.
Related
I am just starting out with ScalaTest and following http://www.scalatest.org/quick_start page
I followed the steps as outlined (by downloading the jar file linked above the code)
and the code fails
unittest vi ExampleSpec.scala
➜ unittest scalac -cp scalatest-app_2.13-3.0.8.jar ExampleSpec.scala
➜ unittest scala -cp scalatest-app_2.13-3.0.8.jar org.scalatest.run ExampleSpec
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoClassDefFoundError: scala/xml/NamespaceBinding
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1368)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24(Runner.scala:1033)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24$adapted(Runner.scala:1011)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1509)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1011)
at org.scalatest.tools.Runner$.main(Runner.scala:827)
at org.scalatest.run$.main(run.scala:120)
at org.scalatest.run.main(run.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at scala.reflect.internal.util.ScalaClassLoader.$anonfun$run$2(ScalaClassLoader.scala:105)
at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:40)
at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:37)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:130)
at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:105)
at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:97)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:130)
at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:29)
at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:43)
at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:34)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:91)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:108)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassNotFoundException: scala.xml.NamespaceBinding
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 29 more
My Scala Version is
➜ unittest scala -version
Scala code runner version 2.13.1 -- Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc.
I thought the error is because scala-xml is a separate project than Scala, so I downloaded the jar file from https://mvnrepository.com/artifact/org.scala-lang/scala-xml/2.11.0-M4
Next, I tried the entire process again and it fails with different error
unittest scala -classpath "scalatest-app_2.13-3.0.8.jar:scala-xml-2.11.0-M4.jar" org.scalatest.run ExampleSpec
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoClassDefFoundError: scala/Serializable
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:515)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:423)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:417)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:416)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1368)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24(Runner.scala:1033)
at org.scalatest.tools.Runner$.$anonfun$runOptionallyWithPassFailReporter$24$adapted(Runner.scala:1011)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1509)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1011)
at org.scalatest.tools.Runner$.main(Runner.scala:827)
at org.scalatest.run$.main(run.scala:120)
at org.scalatest.run.main(run.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at scala.reflect.internal.util.ScalaClassLoader.$anonfun$run$2(ScalaClassLoader.scala:105)
at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:40)
at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:37)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:130)
at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:105)
at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:97)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:130)
at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:29)
at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:43)
at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:34)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:91)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:108)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassNotFoundException: scala.Serializable
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 39 more
Could someone please help me understand what the issue is?
Thank you
UPDATE (SOLVED)
As per the comment from #J0HN and answer from #Mario, I was able to solve the issue
➜ unittest ll
total 17608
-rw-r--r-- 1 harit staff 504B Nov 21 17:15 ExampleSpec.scala
-rw-r--r--# 1 harit staff 555K Nov 22 10:35 scala-xml_2.13-1.2.0.jar
-rw-r--r--# 1 harit staff 7.9M Nov 21 16:59 scalatest-app_2.13-3.0.8.jar
➜ unittest scalac -classpath "scalatest-app_2.13-3.0.8.jar:scala-xml_2.13-1.2.0.jar" ExampleSpec.scala
➜ unittest scala -classpath "scalatest-app_2.13-3.0.8.jar:scala-xml_2.13-1.2.0.jar" org.scalatest.run ExampleSpec
Run starting. Expected test count is: 2
ExampleSpec:
A Stack
- should pop values in last-in-first-out order
- should throw NoSuchElementException if an empty stack is popped
Run completed in 506 milliseconds.
Total number of tests run: 2
Suites: completed 1, aborted 0
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
➜ unittest
I have downloaded scala-xml_2.13-1.2.0.jar from this page
Scala 2.13 decoupled scala-xml from the standard library:
The following modules are no longer included in the distribution:
scala-xml, scala-parser-combinators, scala-swing. They are
community-maintained and published to Maven Central.
As suggested by J0HN, download scala-xml_2.13 and try the following command
scala -cp scalatest-app_2.13-3.0.8.jar:scala-xml_2.13-1.2.0.jar org.scalatest.run ExampleSpec
Here's a brilliant web talk by J. A. De Goes: https://www.youtube.com/watch?v=sxudIMiOo68 - highly recommended for everyone interested in functional programming
And here's accompanying code gist:
https://gist.github.com/jdegoes/1b43f43e2d1e845201de853815ab3cb9
When I run $ scalac fpmax.scala, it compiles everything to a new directory fpmax
But then when I run scala App0, it gives me error:
Exception in thread "main" java.lang.NoClassDefFoundError: App0 (wrong name: fpmax/App0)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
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.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at scala.reflect.internal.util.ScalaClassLoader.$anonfun$tryClass$1(ScalaClassLoader.scala:45)
at scala.util.control.Exception$Catch.$anonfun$opt$1(Exception.scala:242)
at scala.util.control.Exception$Catch.apply(Exception.scala:224)
at scala.util.control.Exception$Catch.opt(Exception.scala:242)
at scala.reflect.internal.util.ScalaClassLoader.tryClass(ScalaClassLoader.scala:45)
at scala.reflect.internal.util.ScalaClassLoader.tryToLoadClass(ScalaClassLoader.scala:39)
at scala.reflect.internal.util.ScalaClassLoader.tryToLoadClass$(ScalaClassLoader.scala:39)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.tryToLoadClass(ScalaClassLoader.scala:125)
at scala.reflect.internal.util.ScalaClassLoader$.classExists(ScalaClassLoader.scala:150)
at scala.tools.nsc.GenericRunnerCommand.guessHowToRun(GenericRunnerCommand.scala:36)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:55)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:18)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:42)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
I run scala 2.12.6.
What would be correct way to run this code snippet?
I had to edit it a bit to run App0.
Change def main: Unit to def main(args: Array[String]): Unit, so that it has main method with args as per Scala spec.
Let's compile it:
scala fpmax.scala. Indeed, this will create fpmax directory with all classes in it
Then run the App0:
scala fpmax.App0 5.50 ✔ 12:21 19.03.19
What is your name?
Alex
Hello, Alex, welcome to the game!
Dear Alex, please guess a number from 1 to 5:
4
You guessed wrong, Alex! The number was: 3
Do you want to continue, Alex?
n
Note, I am NOT going inside the fpmax directory with classes
I am trying to submit a job to spark on my machine as so:
$ spark-submit --master local --class ai.affable.flint.Foo target/scala-2.11/flint.jar
However, this fails with the following error:
java.lang.ClassNotFoundException: ai.affable.flint.Foo
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
I have verfied that the JAR file exists and has a class called Foo:
$ jar tvf ./target/scala-2.11/flint.jar | grep Foo
2003 Fri Dec 14 20:53:40 MYT 2018 ai/affable/flint/Foo.class
...
This baffles me because:
a) the JAR exists b) the class exists in the jar 3) I have specified the fully qualified path and double checked for any path errors or mispellings.
Does anyone know what I am missing?
EDIT:
I got it to work by recreating the project in a fresh directory.I literally copy pasted the code and repeated the steps.
I will still like to know what I can do in situations like this short of recreating the project.
I am getting the following exception while trying to run the ssoadm .setup script. This is with openam13 snapshot version i got on 01/04/2016. It worked before that. Can anyone point me to what might be the issue?
Executing command "/Users/sso-config/target/ssoadmintools/setup --path /apps/openam/server --log /apps/openam/log --acceptLicense --debug /apps/openam/debug" in working directory target/ssoadmintools/
Exception in thread "main" java.lang.NoClassDefFoundError: org/forgerock/services/TransactionId
at org.forgerock.openam.audit.context.AuditRequestContext$1.initialValue(AuditRequestContext.java:35)
at org.forgerock.openam.audit.context.AuditRequestContext$1.initialValue(AuditRequestContext.java:32)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:160)
at java.lang.ThreadLocal.get(ThreadLocal.java:150)
at org.forgerock.openam.audit.context.AuditRequestContext.get(AuditRequestContext.java:124)
at org.forgerock.openam.audit.context.AuditRequestContext.createSubTransactionIdValue(AuditRequestContext.java:160)
at org.forgerock.openam.ldap.LDAPRequests.newSimpleBindRequest(LDAPRequests.java:54)
at org.forgerock.openam.ldap.LDAPUtils.newConnectionFactory(LDAPUtils.java:249)
at org.forgerock.openam.ldap.LDAPUtils.newFailoverConnectionFactory(LDAPUtils.java:200)
at com.iplanet.services.ldap.DSConfigMgr.getNewFailoverConnectionFactory(DSConfigMgr.java:324)
at com.iplanet.services.ldap.DSConfigMgr.getNewConnectionFactory(DSConfigMgr.java:289)
at com.sun.identity.setup.Bootstrap.getConfiguration(Bootstrap.java:190)
at com.sun.identity.setup.Bootstrap.load(Bootstrap.java:136)
at com.sun.identity.tools.bundles.Main.main(Main.java:143)
Caused by: java.lang.ClassNotFoundException: org.forgerock.services.TransactionId
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 14 more
Command process exited with value 1
Can you try running the setup command from the directory where the script is located instead of using the absolute path to the script?
Try this:
./setup --path /apps/openam/server --log /apps/openam/log --acceptLicense --debug /apps/openam/debug
Instead of this:
/Users/sso-config/target/ssoadmintools/setup --path /apps/openam/server --log /apps/openam/log --acceptLicense --debug /apps/openam/debug
My guess is that java cannot find some libraries in the classpath when you use the absolute path.
I've had an auto-generated unit test file as follows:
package com.yuanjianlvye.szws
import grails.test.mixin.*
import org.junit.*
/**
* See the API for {#link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
#TestFor(ScreenResolutionService)
class ScreenResolutionServiceTests {
void testSomething() {
fail "Implement me"
}
}
If I run the unit test with grails command in GGTS as follows: "test-app com.yuanjianlvye.szws.ScreenResolutionService", I can get the expected answer.
Loading Grails 2.2.1
| Environment set to test.....
| Compiling 1 source files..
| Compiling 1 source files.....
| Running 1 unit test... 1 of 1
| Failure: testSomething(com.yuanjianlvye.szws.ScreenResolutionServiceTests)
| junit.framework.AssertionFailedError: Implement me
at junit.framework.Assert.fail(Assert.java:50)
at com.yuanjianlvye.szws.ScreenResolutionServiceTests.testSomething(ScreenResolutionServiceTests.groovy:15)
| Completed 1 unit test, 1 failed in 207ms
However, if I run the unit test by right clicking the file and select "Run As->JUnit Test" in the popup menu, I got the following error message:
Class not found com.yuanjianlvye.szws.ScreenResolutionServiceTests
java.lang.ClassNotFoundException: com.yuanjianlvye.szws.ScreenResolutionServiceTests
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Does anybody have any idea about this?
I've experienced this periodically. Stopping any 'grails run-app' commands from running in the background and cleaning the app using the 'Project/Clean...' menu option sometimes helps.