solr - JUnit、向后兼容性和 SOLR 测试

标签 solr junit backwards-compatibility

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

Testing Solr via Embedded Server

因此,

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

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

最佳答案

公共(public)错误

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

正如 official solr embbeded uri 上所说:

The simplest, safest, way to use Solr is via Solr's standard HTTP interfaces. Embedding Solr is less flexible, harder to support, not as well tested, and should be reserved for special circumstances.



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

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

要在 maven 构建中运行 solr 服务器,您可以使用 CARGO:
- 启动我们正在使用的构建和单元测试maven
- 我们在 Solr 上自动启动测试
- 我们在启动测试时“即时”启动一个 solr 实例,并使用 conain Maven 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>

关于solr - JUnit、向后兼容性和 SOLR 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9117769/

相关文章:

java - 安装Tomcat + Solr问题

django - Django-haystack 使用 Solr 索引列表而不是原始数据

java - 当存在来自父类(super class)的依赖注入(inject)时,如何设置测试?

Java - 如何对主方法依赖项进行单元测试?

python - 从什么时候开始在 Python 中存在 bytes() 函数?

Solr:将索引存储在不同的服务器上

tomcat - 如何在 solrconfig.xml 中指定分片编号/zookeeper 路径?

java - 为什么 JUnit 4.11 在 Ant 构建文件中不工作,但 JUnit 4.8.2 工作正常?

java - 仅更改方法时出现本地类不兼容错误

ruby - 在 Sinatra 中检测浏览器