我一直在开发一个简单的Java Web应用程序来部署到OpenShift中。 虽然我的JUnit测试在Eclipse上运行localy,但在推入git存储库后会被跳过。我加了詹金斯,但仍然是一样的。我不知道我应该有什么标记或配置文件?
这是我的pom.xml内容:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kia</groupId>
<artifactId>kia</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>kia</name>
<repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>kia</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
这是我的测试类:
package info.zamanifar.mysite.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.junit.Test;
import static org.junit.Assert.*;
public class JDBCConnectionTest {
@Test
public void getConnectionTest() {
try {
String dbHost = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
String user = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
String password = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
StringBuilder dbURL = new StringBuilder("jdbc:mysql://");
dbURL.append(dbHost).append("/").append("kia");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(dbURL.toString(),user,password);
assertNotNull("Failed to create JDBC connection!", con);
con.close();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
来自Jenkins的和控制台输出:
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ kia ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ kia ---
[INFO] Packaging webapp
答案 0 :(得分:1)
如果我们谈论Openshift,Jenkins很高兴知道DEFAULT构建脚本中发生了什么:
转到您的作业配置,在Execute Shell部分中,您可以看到:
# Build/update libs and run user pre_build and build
gear build
触发操作的内容(请参阅构建日志)
+ gear build
Found pom.xml... attempting to build with 'mvn -e clean package -Popenshift -DskipTests'
因此,您需要在maven test
gear build
保存并触发作业
祝你好运:)答案 1 :(得分:0)
你写了什么应该触发测试?您是否在其中一个操作挂钩中放置了一些代码来运行测试?