Running both scalatest tests and junit tests with maven plugin

4,542 views
Skip to first unread message

pe...@vagaband.co

unread,
Oct 20, 2013, 7:22:39 PM10/20/13
to scalate...@googlegroups.com
I have an existing project that has both junit tests and newer scalatests within a maven project. I'm using scalatest-maven-plugin but it seems to only run scalatests and not junit tests. Is there a way to get it to run both type of tests? If I added <junitClasses> field, it will run junit tests but will skip scalatests. I want to run both and preferably not have to list every test class in the pom. Is there a way to do this?

Thanks,
Peter

Bill Venners

unread,
Oct 22, 2013, 4:52:18 PM10/22/13
to scalate...@googlegroups.com
Hi Peter,

Sorry, Google groups decided your email was likely spam, and didn't notify me that it was sitting there until today. Hopefully you figured out a solution already, but the lowdown is:

If a jUnitClasses element is specified in the pom, the scalatest-maven-plugin just adds those specified classes as -j options in the argument list passed to Runner.  It doesn't affect how any other arguments are processed.

But if classes are specified like that then Runner treats them as a list of suites to run, and doesn't do any further discovery, so unless some scalatest suites are specified, either individually or using membersOnlySuites or wildcardSuites or globs, then only the junit classes will get run.

More details here:


Let me know if that solves the problem. 

Thanks.

Bill


--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Bill Venners
Artima, Inc.
http://www.artima.com

pe...@vagaband.co

unread,
Oct 24, 2013, 11:33:09 AM10/24/13
to scalate...@googlegroups.com
Hi Bill,

Actually I have not been able to figure it out. I must be missing something very simple. I was just experimenting with junitClasses option to see whether it helps but like you said that's not intended for what I'm looking for.

I'm looking to run both scalatest/junit tests without having to specify individual tests in the pom. I have the pom configured like this ->

            <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <version>1.0-RC1</version>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <filereports>WDF TestSuite.txt</filereports>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <parallel>true</parallel>
                            <tagsToExclude>Integration-Test</tagsToExclude>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <parallel>false</parallel>
                            <tagsToInclude>Integration-Test</tagsToInclude>
                            <systemProperties>
                                <integration.test.host>${integration.test.host}</integration.test.host>
                                <integration.test.port>${integration.test.port}</integration.test.port>
                            </systemProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

And I have regular junit tests under src/test/java and scalatests under src/test/scala. With this it's only picking up scalatests. Is there something additional I need to do to also pick up the junit tests from src/test/java?

Thanks,
Peter

PS - ScalaTest is the only tool that restored my faith in testing frameworks... it's a joy to work with.

Bill Venners

unread,
Oct 24, 2013, 12:51:20 PM10/24/13
to scalate...@googlegroups.com
Hi Peter,

ScalaTest doesn't currently discover JUnit tests. You have to explicitly name them. We are looking into how Surefire discovers JUnit tests. I'm guessing they look for @Test, etc., annotations, but we'll investigate. In the meantime, I wonder if you can use Surefire to discover and run the JUnit ones and ScalaTest to discover and run the ScalaTest ones. The other thing to try is to see if JUnit has a programmatic way (some API) to discover JUnit tests and wrap that in a Suite that you explicitly ask the ScalaTest Maven Plugin to run. I'll keep you posted on what we find out. Let me know if you discover anything in the meantime.

Bill

Matthew Farwell

unread,
Oct 24, 2013, 4:03:29 PM10/24/13
to scalate...@googlegroups.com
Just for information, JUnit itself doesn't do discovery of JUnit tests. The heart of Maven Surefire is https://github.com/apache/maven-surefire/blob/master/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java.

There is a library called ClasspathSuite which allows you to create a Suite which scans the classpath: http://johanneslink.net/projects/cpsuite.jsp

Have fun,

Matthew Farwell.

Bill Venners

unread,
Oct 24, 2013, 4:17:00 PM10/24/13
to scalate...@googlegroups.com
Hi Matthew,

Thanks! That helps.

Bill

Eugene Platonov

unread,
Apr 21, 2014, 10:12:40 AM4/21/14
to scalate...@googlegroups.com
Hi Bill,
is there any progress on this matter?

~
Best Regards,
Eugene

Bill Venners

unread,
Apr 21, 2014, 10:59:57 AM4/21/14
to scalate...@googlegroups.com

Hi Eugene,

We implemented a solution, but I didn't merge it in because I felt it was the wrong way to do it.  I am on a phone right now so can't easily point you to it,  but if you go look at the pull requests for scalatest on github you should see it.  It does discovery of all JUnit tests On the classpath if you specify -J on the command line. I think it may be better to have -J mean include also discover JUnit tests based on the-s, -m, -w params so you can be more precise about what runs. But I also wasn't sure that might be to course grained,  so we haven't fine further.  If so, though, i Was not sure how best to incorporate that into the command line.  What would you (and others with am interest) ideally want?

Bill

For more options, visit https://groups.google.com/d/optout.

Marcelo Turrin

unread,
Nov 24, 2014, 9:11:26 PM11/24/14
to scalate...@googlegroups.com
Hello,
I'm having a similar necessity and as I think this have not been move forward since the last post let me see if I can at least tell my case that I assume could be common.
My team has been developing a java application for the last 3 years, is a distributed chain of web rest services that make a product. Without going to much into it is just a lot of moving parts (with java, groovy, storm, elastic search, etc).
We wanna start moving towards developing in scala, but as we have a lot done and to start easying our way in we decided to start coding test to get the hang of the language.
Now we are trying to integrate it and what it is stopping us to move forward is that we cannot run our old test in Java (and Groovy) via maven if we add scala test (as it requires to disable surefire).
And adding each test to the pom is not an option as we have hundreds and modifying the pom each time we need to add a test is not practical.

So the necessity is simply put is that we run mvn clean install we need this command to discover (as surefire doues) and run all test: scala, java and groovy so our developers and specially our continues integration scheme can create test in scala without loosing what they already have.

I know that perhaps this is not one of the priorities for your project so I wanted to ask if  this was on your roadmap or you think it will be or if you have an alternative I could have missed to finally be able to come up with a decisson on how to move forward with this scala integration posibility.

Thank you very much 

Łukasz Sanek

unread,
Mar 23, 2015, 7:57:45 PM3/23/15
to scalate...@googlegroups.com
Hi,
I've had a similar problem and I solved it by simply running both JUnit and ScalaTest tests with maven-surefire-plugin (the scalatest-maven-plugin is not needed). You can have a look at the sample Maven project here: https://github.com/s4nk/scalatest-maven-template

Lukasz

Juancho J

unread,
Oct 14, 2015, 5:48:58 PM10/14/15
to scalatest-users
Hi Lukasz,

I have followed the pattern you reference. The java tests still run. However, the scala ones don't. Here's the snippet of my pom:

<plugin>

 
<groupId>org.apache.maven.plugins</groupId>

 
<artifactId>maven-surefire-plugin</artifactId>

 
<version>2.16</version>

 
<configuration>

 
<threadCount>5</threadCount>

 
<parallel>classes</parallel>

 
<reportsDirectory>target/testng-surefire-reports/</reportsDirectory>

 
<excludedGroups>cleanup</excludedGroups>

 
<includes>

         
<include>**/*Spec.*</include>

 
</includes>

 
</configuration>

 
</plugin>

 
<plugin>

 
<groupId>net.alchim31.maven</groupId>

 
<artifactId>scala-maven-plugin</artifactId>

 
<executions>

                     
<execution>

                         
<id>scala-test-compile</id>

                         
<phase>process-test-resources</phase>

                         
<goals>

                             
<goal>add-source</goal>

                             
<goal>testCompile</goal>

                         
</goals>

                     
</execution>

                   
</executions>

 
</plugin>


Could you possibly help me w/ this?

Reply all
Reply to author
Forward
0 new messages