Reputation: 6292
I am writing a simple project using maven, scala and junit.
One problem I found is that my tests cannot find org.junit.framework.Test. The test file:
import org.junit.framework.Test
class AppTest {
@Test
def testOK() = assertTrue(true)
@Test
def testKO() = assertTrue(false)
}
returns error:
[WARNING]..... error: object junit is not a member of package org
[WARNING] import org.junit.framework.Test
[WARNING] ^
I did have junit added as a dependency and it clearly sits inside my repository.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
Can someone tell me what causes this?
Many thanks
Upvotes: 2
Views: 5562
Reputation: 61705
As @nico_ekito says, your import is incorrect, and should be org.junit.Test
.
But this doesn't explain your problem:
[WARNING]..... error: object junit is not a member of package org
[WARNING] import org.junit.framework.Test
[WARNING] ^
So it can't find org.junit. This means that org.junit isn't in the classpath when you're compiling the tests. So either your dependency tree is screwed up, or the actual jar is.
Try
mvn dependency:list
This should result in something like:
[INFO] The following files have been resolved:
[INFO] junit:junit:jar:4.8.1:test
Ensure that you've got no other junit libraries being resolved. If everything looks ok, check the contents of your junit jar. It should contain the class org.junit.Test. If it doesn't, you've got a corrupted repo, or you're not looking in the right place. The easiest way to know this is to use:
mvn dependency:copy-dependencies
which creates target/dependency with a copy of the dependencies. You can look at the jar there.
Upvotes: 2
Reputation: 21564
The package for the Test
class in JUnit 4.8.1 is junit.framework.Test
and not org.junit.framework.Test
.
Upvotes: 1