In a Tycho build, ScalaTests don't run and Java-based JUnit tests don't find any Scala references

23 views
Skip to first unread message

Jens Rabe

unread,
Feb 27, 2017, 5:55:08 AM2/27/17
to Scala IDE User
Despite the recommendation to use web technologies instead of RCP, I am now using RCP for my application because RCP brings a lot of stuff readily made where I would have to reinvent many wheels doing it another way, and I don't have the time to start from scratch.

I now set up a POM-less Tycho build, and have a fragment that contains some tests.

I set up the ScalaTests to run with the JUnitRunner like this:

@RunWith(classOf[JUnitRunner])
class MyTest extends FlatSpec with Matchers {

 
// Test code
}

I added the respective inclusions into my pom.xml (despite it's pom-less, for tests to run, a pom.xml is needed):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   
<modelVersion>4.0.0</modelVersion>
   
<artifactId>com.mycompany.myapp.project.model_test</artifactId>
   
<packaging>eclipse-test-plugin</packaging>
   
<parent>
       
<groupId>com.mycompany.myapp</groupId>
       
<artifactId>com.mycompany.myapp.tests</artifactId>
       
<version>0.0.1-SNAPSHOT</version>
   
</parent>
   
<build>
       
<plugins>
           
<plugin>
               
<groupId>org.eclipse.tycho</groupId>
               
<artifactId>tycho-surefire-plugin</artifactId>
               
<version>0.26.0</version>
               
<configuration>
               
<includes>**/Test*.java,**/*Test.java,**/*TestCase.java,**/Test*.scala,**/*Test.scala,**/*TestCase.scala</includes>
               
</configuration>
           
</plugin>
       
</plugins>
   
</build>
</project>

When I run the build, I get:

Root exception:
java
.lang.RuntimeException: Unable to create test class 'com.mycompany.myapp.tests.MyTest.scala'
...
Caused by: java.lang.ClassNotFoundException: com.mycompany.myapp.tests.MyTest.scala

I can run the test from Eclipse just fine by right-clicking the test and using the appropriate option in the "Run As" menu.

When removing the Scala inclusions and adding a simple Java-based test:

import org.junit.Test;

public class FooTest {

   
@Test
   
public void foo() {

   
}
}

this works.

However, when I try to access anything written in Scala, it cannot resolve the references.

What am I missing?
Message has been deleted

Jens Rabe

unread,
Mar 21, 2017, 9:34:36 AM3/21/17
to Scala IDE User
Since I could not get it to work, and there seems to be no one with a clue, I wrote a small JUnit runner that starts the ScalaTests and gathers the results, and so, Maven recognizes this Java-based class. It's not beautiful, but at least a workaround that works.
Reply all
Reply to author
Forward
0 new messages