It turns out I have to tell Spring that it is using JUnit 4 by
annotating my class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/test/resources/META-INF/applicationContext.xml"})
public class SettingsDAOTest extends AbstractJpaTests {
Before the AbstractJpaTests superclass set everything up and injected
what I needed into my test class. Now all of that is gone, so I had to
add the @ContextConfiguration annotation and @Autorwired to inject the
DAO. Now it doesn't recognize the entity I am trying to merge with JPA.
I also found out that @RunWith(SpringJUnit4ClassRunner.class) only
works with Junit 4.4 and newer. But, surefire maven2 plugin causes
trouble when using Junit 4.5 so you have to downgrade to 4.4:
http://jira.springframework.org/browse/SPR-5145
Too much trouble. I'm going to use JUnit 3 style configs for this class
so that AbstractJpaTest actually works.
Ryan
Ryan de Laplante wrote:
Actually, it must be using JUnit 4 because I have a test suite
completely configured with annotations. Also, when one of my unit
tests throws an untrapped exception I see this in the stack tract:
java.lang.NullPointerException
at
... notice Spring Framework is doing something. My test class extends
AbstractJpaTestCase
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at
org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.access$001(AbstractAnnotationAwareTransactionalTests.java:71)
... Notice surefire Junit4TestSet
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at
So this must be a spring problem.
Thanks,
Ryan
Ryan de Laplante wrote:
Hi,
My junit tests work if I prefix test method names with the word
test. If I don't do that and rely on the @Test annotation then the
test methods are not executed.
I have this in my POM:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
and in my build section I have:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<includes>
<!-- Only execute test suites -->
<include>**/*TestSuite.java</include>
</includes>
</configuration>
</plugin>
</plugins>
So I am using the latest version of surefire. Any ideas why it's not
using Junit 4?
Thanks,
Ryan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]