I wonder if there is any best practice for junit testing of Solr 3.6. I want to automate testing of the Solr schema. Earlier posts mentioned the EmbeddedSolrServer. This class seems to have been abandoned from any version between 1.4 an 3.6. I use Spring 3.0.x and Maven for the project. The options I considered are:
- writing a Junit Test Runner
- put the jetty startup code in the @Before or @BeforeClass method
- start a solr server in maven (probably not a good option)
- put some code in the spring test-context
I'm using https://github.com/moliware/travis-solr for my tests, maybe it's useful for you too.
I've used something similar to what's on this page to run these kinds of tests, all done with EmbeddedSolrServer on Solr 3.4.0. This is a simple approach, but if you want to automate Solr schema testing, it could be enough and isn't hard to implement.
It basically boils down to:
Adding references to
junit
,solr-core
,slf4j-simple
andservlet-api
to yourpom.xml
:And as an example test case, he adds this:
edit: I haven't used Solr in quite a while, but I think this could still be a good starting point.
This is my take on it. It doesn't extend AbstractSolrTestCase, just a regular test class.
My POM has the following dependencies:
I've set up a separate project to keep all my Solr config in and run tests against it. The directory structure is:
This seems to work well for me. This set up will also let you write tests using HttpSolrServer to test a remote server's schema.
Also, note the
server.commit()
call in the middle of the test. This needs to be there otherwise the Solr transaction isn't complete and the new document won't be visible.