gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:42:15 25 4
gpt4 key购买 nike

嗨:这是一个两部分的问题 - 首先 - 我注意到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com