【问题标题】:JUnit, backwards compatibility, and SOLR testingJUnit、向后兼容性和 SOLR 测试
【发布时间】:2012-02-02 18:23:20
【问题描述】:

嗨:这是一个由两部分组成的问题 - 首先 - 我注意到 JUnit 4.7 构建错误,并发现 JUnit 实际上不向后兼容:

Testing Solr via Embedded Server

因此,

是否可以在其他最新版本(使用最新的 Junit)8 版本中使用 Junit 4.7 进行某些测试?

当然 - 我也想知道,总的来说,JUnit 是否向后兼容?在我的例子中,SOLR 的基本单元测试类似乎依赖于一些在 JUnit 4.7 中可能出现的奇特技巧,这些技巧不再受支持。

【问题讨论】:

  • 一般来说,JUnit 是向后兼容的。如果您能提及从 4.7 升级到 4.8 时遇到的特定问题,这将很有帮助,以便我们可以告诉您是否有问题,或者是否是 Solr 中的问题。
  • 好吧...也许我会尝试制作一个简单的、可重现的版本并报告此错误。

标签: solr junit backwards-compatibility


【解决方案1】:

常见错误

你的bug很常见,官博解释的很清楚。小心Solr嵌入式服务器,SOLR本身不推荐!!!

正如official solr embbeded uri上所说:

使用 Solr 最简单、最安全的方法是通过 Solr 的标准 HTTP 接口。嵌入 Solr 不太灵活,更难支持,而不是 经过良好测试,应保留用于特殊情况。

选择题:“继续运行单元测试服务器”或“即时”运行它

我建议你做和我们一样的事情来进行单元测试, - 运行专用的 solr 服务器,或 - 即时运行一个

要在 maven 构建中运行 solr 服务器,您可以使用 CARGO: - 要启动我们正在使用的构建和单元测试maven - 我们在 Solr 上自动启动测试 - 我们在启动测试时“即时”启动一个 solr 实例并使用 conainMaven Cargo 关闭它 - 在 junit 结束时,我们关闭 Cargo ! :)

简单干净! 享受:)

cargo maven 代码示例:

<plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.8</version>
            <executions>
                <execution>
                    <id>start-container</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-container</id>
                    <phase>package</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configuration>
                    <properties>
                        <cargo.servlet.port>8966</cargo.servlet.port>
                    </properties>
                </configuration>

                <container>
                    <containerId>jetty7x</containerId>
                    <type>embedded</type>
                    <systemProperties>
                        <solr.solr.home>${basedir}/target/solr</solr.solr.home>
                        <!-- log4j.configuration>file://${basedir}/src/test/resources/log4j.properties</log4j.configuration -->
                        <log4j.debug>true</log4j.debug>
                        <net.sourceforge.cobertura.datafile>target/cobertura/cobertura.ser</net.sourceforge.cobertura.datafile>
                    </systemProperties>
                    <dependencies>
                        <!-- SLF4J -->
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-api</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>jcl-over-slf4j</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>jul-to-slf4j</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-log4j12</artifactId>
                        </dependency>
                        <!-- Log4j -->
                        <dependency>
                            <groupId>log4j</groupId>
                            <artifactId>log4j</artifactId>
                        </dependency>
                    </dependencies>
                </container>
                <deployables>
                    <deployable>
                        <groupId>org.apache.solr</groupId>
                        <artifactId>solr</artifactId>
                        <type>war</type>
                        <properties>
                            <context>/solr</context>
                        </properties>
                    </deployable>
                </deployables>
            </configuration>
        </plugin>

【讨论】:

    猜你喜欢
    • 2011-10-28
    • 2023-04-03
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    相关资源
    最近更新 更多