【问题标题】:Using "test" DB in GUI integration tests在 GUI 集成测试中使用“测试”数据库
【发布时间】:2014-08-25 12:08:22
【问题描述】:

我有一个 Spring MVC + JPA/Hibernate 应用程序。该应用程序有一些 GUI (Selenium) 测试。我使用tomcat7-maven-plugin 为这些测试部署我的应用程序:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <fork>true</fork>
            </configuration>
        </execution>
        <execution>
            <id>tomcat-shutdown</id>
            <goals>
                <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>

此设置适用于生产数据库,但我需要使用另一个数据库进行这些测试。我的数据库连接设置在 Spring 配置和 .properties 文件中定义。

部署应用程序进行 GUI 测试时如何更改数据库连接设置?

【问题讨论】:

    标签: spring spring-mvc jpa selenium maven-tomcat-plugin


    【解决方案1】:

    1) 在 Spring 配置中创建两个 Spring 配置文件:一个用于生产(包含生产数据库的数据库连接设置),另一个用于集成测试(包含测试数据库的数据库连接设置)。

    2) 将以下配置添加到tomcat7-maven-plugin:

    <configuration>
        <systemProperties>
            <!--Replace `nameOfYourSpringTestProfile` with the name of your actual test profile. -->
            <spring.profiles.active>nameOfYourSpringTestProfile</spring.profiles.active>
        </systemProperties>
    </configuration>
    

    此配置将在部署的应用程序中设置spring.profiles.active系统变量,这将激活测试配置文件和相应的数据库连接设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多