我在 Junit 测试中使用 Maven。我使用的是标准的 Maven 项目结构,我可以在 Eclipse 中运行“作为 Junit 测试运行”,它们都成功了,但是如果我想运行 Maven 测试/安装,那么测试没有运行,导致错误“无法初始化类 main.sushi.persistence.Persistor”。
这是我们的项目树:
??? pom.xml
??? src
? ??? main
? ? ??? java
? ? ? ??? main
? ? ? ??? sushi
? ? ? ??? persistence
? ? ? ??? DatabaseEnvironments.java
? ? ? ??? META-INF
? ? ? ? ??? persistence.xml
? ? ? ? ??? persistence_template.xml
? ? ? ??? Persistor.java
? ? ??? resources
? ??? test
? ??? java
? ? ??? META-INF
? ? ? ??? persistence.xml
? ? ? ??? persistence_template.xml
? ? ??? test
? ? ??? sushi
? ? ??? persistence
? ? ??? ProcessPersistorTest.java
? ? ??? TestPersistor.java
? ??? resources
??? target
??? classes
? ??? META-INF
? ? ??? MANIFEST.MF
? ? ??? maven
? ? ??? sushi
? ? ??? SushiPersistence
? ? ??? pom.properties
? ? ??? pom.xml
? ??? main
? ??? sushi
? ??? persistence
? ??? DatabaseEnvironments.class
? ??? META-INF
? ? ??? persistence.xml
? ? ??? persistence_template.xml
? ??? Persistor.class
??? generated-sources
? ??? annotations
??? surefire
??? surefire-reports
? ??? TEST-test.sushi.persistence.ProcessPersistorTest.xml
? ??? TEST-test.sushi.persistence.TestPersistor.xml
? ??? test.sushi.persistence.ProcessPersistorTest.txt
? ??? test.sushi.persistence.TestPersistor.txt
??? test-classes
??? META-INF
? ??? persistence.xml
? ??? persistence_template.xml
??? test
??? sushi
??? persistence
??? ProcessPersistorTest.class
??? TestPersistor.class
Run Code Online (Sandbox Code Playgroud)
绒球:
<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>
<groupId>sushi</groupId>
<artifactId>SushiPersistence</artifactId>
<version>SNAPSHOT</version>
<repositories>
<repository>
<id>EclipseLink</id>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>de.hpi-web.sushicommon</groupId>
<artifactId>SushiCommon</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.22</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
src/main/sushi/persistence/META-INF中的资源必须位于src/main/resources下,并且用于测试的相应文件夹必须位于src/test/resources下,而不是src/main/java或src/test/中爪哇。
| 归档时间: |
|
| 查看次数: |
10027 次 |
| 最近记录: |