Scalatest building and running in Intellij, but not building the project when run on the command line with maven - scala

I'm able to run my tests in a spec file individually when using intellij, however when I try running with Maven on the command line the project will not build with a
java.lang.RuntimeException: Unable to load a Suite class that was
discovered in the runpath: project.uitest.spec.aTestFile
error. I've tried restarting everything I can think of, and it works fine on my coworkers computer that has been running the tests for a long time. The issue reproduces on two other new coworkers environments however.
We tried copying the .m2 folder from the working environment onto the new environment machines however still run into the same issue.
We are using the same version of the JRE, and the scala and scalatest versions are specified in our pom.xml file.
We can also ignore the test that won't load and are able to run the tests.
Any insight or ideas of ways to fix this will be greatly appreciated.

What version of ScalaTest are you using?
ScalaTest Maven Plugin 1.0 doesn't support ScalaTest 3
https://github.com/scalatest/scalatest-maven-plugin/issues/27

Related

Weird Build issue with Intellij, Maven, Scala pulgins

I am facing really weird build issue with Intellij, Maven and Scala.
We have scala project, when I package it into jar by running mvn clean, mvn scala:compile and mvn install or package, it generates jar file perfectly but when I deploy this jar to our AWS EMR ec2 instance and when I run that jar with spark-submit command sometimes it complains about
"Error: Failed to load class com.OUR_PACKAGE_NAME.ScalaMainClass"
So I tried to check my code which looks perfectly fine, it complies fine, also it runs fine in my local machine. But sometimes that same generated jar works fine and sometime it does not in AWS EMR ec2 instance. It is not consistent.
So I reverted back my code to previous working stage and started adding my code one by one untill I get this "Failed to load class" problem. Then I encounter that one of the scala class having some issue. Visually code looks fine also it compiles great, but somehow that scala class creates problem when mvn creates jar file and when we run it to EC2.
The weird part is that, when I hit enter and add new blank line before or after problematic line of code, maven generated jar works fine. So I believe there is some hidden character which maven does not like or intellij is not able to uncode properly. And when I takeout that blank line that error appears again.
Could you help me on that?

Cannot build/run Scala project in IntelliJ after packaging with Maven

So my Scala project was working perfectly fine in IntelliJ, then I tried to run package in Maven to obtain a .jar file, which was not working because I was missing a dependency. So I tried to edit pom.xml however reverted it back shortly.
Anyhow, thereafter, without any changes I tried to run my Scala project normally locally and it doesn't work anymore. I get the error:
Error: Can not find or load main class Name.Name
I double checked Edit Configurations in IntelliJ and the main class is specified.
What went wrong? There has been no changes at all except that I tried to package my project using Maven, and then my normal program stopped working.
Solved it by recreating the project from scratch, however I'm still unsure what the cause was.

Cucumber and Eclipse IDE; How to make jar for a test case

I'm a Cucumber and Eclipse beginner and have a few questions and hope you can help me to get through this: I created a sample cucumber test scenario, a sample test steps and a cucumber runner. The scenarios runs fine within eclipse IDE (Neon). I used Maven as the dependency manager. I also installed the Maven command line module. The step code is Java.
Here is the (basic) question: How do I create a jar file from my cucumber test scenario so that execute it via command line so that I can bring the test scenario to Jenkins CI? Is there anything I need to do with Maven BEFORE I can build the jar file?
Thanks a lot folks!
If you run Cucumber using the JUnit runner, then all you have to do to run from a command line is to execute Maven and make sure you invoke a life cycle phase that includes running the unit tests. One way would be
mvn test
An example that might get you up and running can be found at
https://github.com/cucumber/cucumber-java-skeleton

Misterious `classMethod` test in Gradle Scala unit testing with JUnit 4

I'm having an issue with Gradle, JUnit and Scala test execution, in our Scala language extension for Vert.x. Recently we upgraded from Vert.x 2.1.RC1 to 2.1.RC2, we started seeing that in some environments such as our Cloudbees instance, test execution looks up a phantom method called classMethod in a test class, which does not exist, and the test times out. As a result of that, the rest of tests fail.
In this console instance, you can see:
org.vertx.scala.tests.core.http.HttpTest > classMethod FAILED
java.lang.AssertionError: Timed out waiting for test to complete
We have no idea what this classMethod is, where it's coming from...etc. Even more spooky is that I'm unable to replicate it neither in my OSX nor Linux (RHEL7) environments, both with JDK 1.7u45 and 1.7u51.
The only way we've found to be to fix it so far is to revert to Vert.x 2.1.RC1 (see console of run with RC1), but we're really unable to see the link between this and this misterious classMethod.
We've tried upgrading to Gradle 1.11 in case it's an issue with Gradle itself but no luck. We're currently using JUnit 4.11.
The only thing that looks slightly suspicious is how even though the project uses Scala 2.10.4, the Gradle Scala plugin seems to bring in Zinc which appears to need Scala 2.9.2. When I wiped out my .gradle/ folder locally, I didn't see any Scala 2.9.2 being downloaded. I wonder if this is messing up things?
Finally, for this last run when HttpCompressionTest seem to have that classMethod, I've compared the javap output locally with the one in Cloudbees, and they look identical.
I'm out of ideas, any suggestions?
UPDATE: As a last resort, I decided to upgrade to Vert.x 2.1.RC3-SNAPSHOT and it's all back to normal. I've absolutely no idea why, but I'll take it :)
I've seen this behavior caused by (accidentally) having two different versions of the same lib on the classpath. Also, when a particular project is packaged as several different JARs, one of them was down-level from all the rest.

ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven)

I have just upgraded my SpringSource Tools Suite (STS, a variant IDE of Eclipse) to the latest version (v3.6.1). Then all my JUnit unit tests can not be run again. I am getting this error:
Class not found ClassToTest
java.lang.ClassNotFoundException: ClassToTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
According to this blog:
ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven),
it is because of some misconfiguration of Maven plugin in Eclipse. However, in STS 3.6.2 I cannot find this option "Include Modules" in the Maven plugin. How can I fix this problem and re-enable my unit tests?
There are still some back-draws on the current m2e plugin. Unit-test-cases couldn't be run as their including project grouped in a working-set. Following may help:
Right click on project including junit-tests.
Select Maven -> Disable Workspace Resolution
Try then to run your test again.
OK it seems I'll have to answer this question by myself.
The main reason for this problem is still the m2eclipse eclipse plug-in. The new version of this plugin does not support nested modules in one project. If we really need to see multiple modules we have to remove the old one from the package explorer and create a working set and import the project again using the option "import existing maven projects". The eclipse import wizard will pop up a window and ask you which module to be imported. Then we can select all the modules and finish the import. As a result the working set will contain all the modules of your project and treat each module as a separate project, although in the workspace your modules are still in one project. By doing this it resolves all the problems that I have come across in Eclipse related to classpath, such as not being able to search a class or not being able to run the unit tests and get a java.lang.ClassNotFoundException.
For reference, here is an article to teach you how to create a working set:
Working set
I think you can import the project without creating a new working set but the working set will keep all the modules that belong to your project in one set so it is easier to organize.
I wish I had the answer two months ago so I wouldn't have spent much time searching for a solution.
I think I have found the solution, at least this worked for me:
right click on the project and choose 'Maven' -> 'Update Dependencies'
Then when I tried , I did not get ClassNotFoundException .
I tried everything mentioned here and in other posts. Some of the solutions that people proffered were:
Change the output folder for the test classes.
Create a custom builder for the project that would run test-compile from Maven.
Move the Maven dependencies higher in the Order and Export list in the project build path.
There were many, many more but the one that I found to work was as follows:
Close the development environment.
Delete the jars used by the project from my local Maven repository.
Open the IDE.
Build the project.
Run the test.
After hours of beating my head against my keyboard and following suggested solutions, this one worked!
We too faced the same ClassNotFoundException while trying to run JUnit test class. But when we tried using the following steps, it successfully started running.
Select your project.
Click on the project option displayed in toolbar in the eclipse IDE.
Select “clean”.
Now try running the test file.
As a work-around, try running mvn test-compile (either in Eclipse or from the command line), then try running the Junit test within Eclipse.