Type mismatch junit5 #ExtendWith - junit4

so this is probably a really dumb question but I just started to migrate a project from junit 4 to 5 and saw that #RunWith() does not longer exists. It is replaced by #ExtendWith. So I tried to do it like this:
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
import de.msggillardon.services.journal.JournalService;
import de.msggillardon.system.UserContext;
import de.msggillardon.util.ITDeployment;
#ExtendWith(Arquillian.class)
.....
And I get the following exception: "Type mismatch: cannot convert from Class to Class <? extends Extension>
I am a really bloody beginner and have no Idea how I can fix the problem.. So maybe someone could help me or tell me where I can find the necessary Information.
Thank you all.

Unfortunately, you can't use JUnit 4's Runner as your JUnit Jupiter (part of JUnit 5) extensions. That's a completely new API and not compatible.
Although the JUnit Jupiter programming model and extension model will
not support JUnit 4 features such as Rules and Runners natively, it is
not expected that source code maintainers will need to update all of
their existing tests, test extensions, and custom build test
infrastructure to migrate to JUnit Jupiter. From the official JUnit documentation
So for each #RunWith, you need to use/include the JUnit Jupiter extension. In your particular case of Arquilian, I'm not quite sure if there is already an official extension for this.
The following links might help:
https://developer.jboss.org/thread/274569
https://github.com/arquillian/arquillian-core/issues/137

Arquillian now support junit 5.
Replace
#RunWith(Arquallian.class)
with
#ExtendWith(ArquillianExtension.class)
Also add the new dependency
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>1.7.0.Alpha10</version>
</dependency>

Related

Can't import Jena classes

I'm setting up Jena in eclipse. However, when I try to import any class, such as the Model class, I am getting the error "The import com.hp cannot be resolved". I already set up the build path to the Jena library. Below is a picture of my simple setup and as you can see I am getting an error on the import statement.
http://imgur.com/Z1tfF5f
The package tree starts org.apache.jena for Jena version 3 onwards. Your IDE can help by finding the class Model

import scala.swing._ in eclipse giving an error that it is not a member of package scala

Does anybody have any experience with trying to get swing to work in eclipse, I can import it fine into scala using the command line interface, but when i try and use it in an eclipse scala project I get the following error:
import scala.swing._
"object swing is not a member of package scala"
Any help would be much appreciated.
If you are missing the library (as RĂ¼diger said, it is a separate dependency now), you can find how to add it to your build system here (for Scala 2.11):
http://search.maven.org/#artifactdetails|org.scala-lang.modules|scala-swing_2.11|1.0.1|bundle
Look under "Dependency Information", e.g. for sbt if you use that.

Import org.junit cannot be resolved

I have a class file beginning with the following in Eclipse:
package org.jsoup.parser;
import org.junit.Assert.*;
import org.junit.Test;
import org.jsoup.nodes.Document;
import org.jsoup.parser.HtmlTreeBuilder;
However, Eclipse indicates an error saying that org.junit cannot be resolved. I have already modified the project properties to include jUnit 3 in the classpath, so wouldn't know what to do further.
Ideas?
EDIT: I have included jUnit 4 as suggested but to no avail...
If you want to use org.junit.Assert you should include JUnit 4. JUnit 3 uses junit.framework.* packages.

How do I run test groups with Scala + JUnit runner + Maven?

I'm trying to support running tags/groups of tests on the Maven commandline. I think I have the correct syntax setup in my .scala file (see below), but I'm unsure how to actually execute on the commandline. Examples on the web are mostly in Java.
I want to be able to do something like mvn clean test -Dtags:SlowTest,DbTest to run all the tests tagged as "slow" and "db".
I've seen Surefire pom.xml examples out there, but I'm not sure how I'd then tag the Surefire groups in my test code itself.
Ideas?
import org.junit.experimental.categories.Category
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.Tag
class SlowTest extends Tag("com.mycompany.tags.SlowTest")
class DbTest extends Tag("com.mycompany.tags.DbTest")
#RunWith(classOf[JUnitRunner])
#Category(Array(classOf[SlowTest], classOf[DbTest]))
class FunSuiteTest extends FunSuite with DemoHelpers {
test("DemoTest1") {
If you are using the scalatest-maven-plugin you should be able to do something like this:
mvn -DtagsToInclude=SlowTest,DbTest clean test
I might suggest that if you want to do some test in Scala, why dont you try using
SCALA TEST
it is good and easy to use.

Scala eclipse plugin java.lang.ClassNotFoundException

I am using eclipse Version: 3.7.2 with the Scala IDE for Eclipse 2.1.0.nightly-2_09-201203121521-6e8582e. The java version is 1.6.0_31. The OS is Ubuntu 11.10.
I have looked for solutions to this problem, but I have not found one yet. I hope there is not an obvious answer that I have missed.
I have this class (note the package):
package model.x.y
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
#RunWith(classOf[JUnitRunner])
class GibberishTestSuite extends FunSuite {
test("Check Gibberish") {
assert("blah" === "blah")
}
}
I am also using gradle and the source path looks like this (note that the package does not match the directory hierarchy):
.../src/test/scala/model/GibberishTest.scala
Eclipse and gradle generate the coresponding class files:
bin/model/x/y/GibberishTestSuite.class
build/classes/test/model/x/y/GibberishTestSuite.class
This runs fine through gradle, but when I try to run in eclipse, I get
Class not found model.GibberishTestSuite
java.lang.ClassNotFoundException: model.GibberishTestSuite
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
If I change the package to
package model
so that the directory hierarchy and the package name match, then I am able to run the unit test in eclipse. In scala, it is legal for the package structure and the directory structure not to match. However, the mismatch seems to be confusing eclipse or the plugin.
Am I doing something wrong? Am I missing some configuration nuance? Is this scala language feature not supported in eclipse? Will it be supported at some point?
Thank you.
This is an Eclipse (JDT) problem rather than a Scala/scala-ide problem.
There was a bug raised against Eclipse (Package Explorer tree does match declared package), but basically, Eclipse assumes that the hierarchy matches the package names. This will be fixed eventually in the Scala-ide, but the model needs to be changed, to remove the dependency on the JDT. If you want this fixed, it's a good idea to add your vote to the above issue.