JUnit, backward compatibility and SOLR testing

Hey. This is a two-part question. Firstly, I noticed JUnit 4.7 build errors and found that JUnit, in fact, is not backward compatible:

Testing Solr via the Embedded Server

Thus,

Is it possible to use Junit 4.7 for certain tests otherwise up to date (using the latest version of Junit) 8?

Of course, I would also like to know, in general, JUnit backward compatibility? In my case, it seems that the SOLR base unit test class relies on some fancy tricks that were possible in JUnit 4.7, which are no longer supported.

+4
source share
1 answer

community bug

Your mistake is very common, and the official blog explains it clearly. Be careful with the built-in Solr server, it is not recommended by SOLR !!!

As stated in the official solarium :

The easiest, most secure way to use Solr is through the standard Solr protocol HTTP interfaces. Solr embedding is less flexible, more difficult to maintain, and not as well-tested, and should be reserved for special circumstances.

A choice question: "Continue to work unit test server" or run it "on the fly"

I suggest you do the same thing that we do to unit test, - run a dedicated solr server or - run one on the fly

To start the solr server inside the maven assembly, you can use CARGO: - To run the assembly and unit test, we use maven - we will run an automatic test on Solr - we start the test with a live instance on the fly and close it using conain Maven Cargo - At the end of the unit, we close Cargo! :)

Easy and clean! Enjoy :)

Freight maven code example:

<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> 
0
source

Source: https://habr.com/ru/post/1394449/


All Articles