Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing unit tests for Solr plugin using JUnit4, including creating collections

I wrote a plugin for Solr which contains new stream expressions. Now, I'm trying to understand what is the best way to write them unit tests: Unit tests which need to include creation of collections in Solr, so I will be able to check if my new stream expressions return me the right data they suppose.

I saw over the web that there is a class called "SolrTestCaseJ4", but I didn't find how to use it for creating new collections in Solr and add them data and so on...

Can you please recommend me which class may I use for that purpose or any other way to test my new classes?

BTW, we are using Solr 7.1 in cloud mode and JUnit4.

Thanks in advance.

like image 771
Nuriel Zrubavely Avatar asked Dec 21 '17 16:12

Nuriel Zrubavely


People also ask

Can we generate the JUnit report for the test cases generated in TestNG?

TestNG, by default, generates JUnit XML reports for any test execution (in the test-output folder). We can use these XML report files as input for generating a JUnit HTML report.

What is @after in JUnit?

org.junit Annotating a public void method with @After causes that method to be run after the Test method. All @After methods are guaranteed to run even if a Before or Test method throws an exception.


2 Answers

you could use MiniSolrCloudCluster

Here is an example how to create collections (all for unit test):

https://github.com/lucidworks/solr-hadoop-common/blob/159cce044c1907e646c2644083096150d27c5fd2/solr-hadoop-testbase/src/main/java/com/lucidworks/hadoop/utils/SolrCloudClusterSupport.java#L132

like image 55
acesar Avatar answered Oct 22 '22 06:10

acesar


Eventually I found a better class, which simplifies everything and implements more functionality than MiniSolrCloudCluster (actually it contains MiniSolrCloudCluster inside it as a member).

This class called SolrCloudTestCase, and as you can see here, even Solr's source code uses it in their own unit tests.

like image 36
Nuriel Zrubavely Avatar answered Oct 22 '22 05:10

Nuriel Zrubavely