So my first thought is that "unit test + solr integration" is an
oxymoron. In the sense that unit test implies the smallest functional
unit, and solr integration implies multiple units working together.
It sounds like you have two different tasks. the code that generate
queies, you can test that without Solr. If you need to parse some
sort of solr document to generate a query based on it, then mock up
the query. A lot of folks will just use Solr to build a result set,
and then save that on the filesystem. "my_big_result1.xml" and read
it in and feed it to your code.
On the other hand, for you code testing indexing and retrieval, again,
if you can use the same approach to decouple what solr does from your
code. Unless you've patched Solr, you shouldn't need to unit test
Solr, Solr has very nice unit testing built in.
On the other hand, if you are doing integration testing, where you
want a more end to end view of your application, then you probably
already have a "test" solr setup in your environment somewhere that
you can rely on to use.
Spinning up and shutting down Solr for tests can be done, and I can
think of use cases for why you might want to do it, but it does incur
a penalty of being more work. And you still need to validate that
your "embedded/unit test" solr works the same as your integration/test
environment Solr.
Eric
On Mar 27, 2009, at 11:59 AM, Joe Pollard wrote:
Hello,
On our project, we have quite a bit of code used to generate Solr
queries, and I need to create some unit tests to ensure that these
continue to work. In addition, I need to generate some unit tests
that will test indexing and retrieval of certain documents, based on
our current schema and the application logic that generates the
indexable documents as well as generates the Solr queries.
My question is - what's the best way for me to unit test our Solr
integration?
I'd like to be able to spin up an embedded/in-memory solr, or that
failing just start one up as part of my test case setup, fill it
with interesting documents, and do some queries, comparing the
results to expected results.
Are there wiki pages or other documented examples of doing this? It
seems rather straight-forward, but who knows, it may be dead simple
with some unknown feature.
Thanks!
-Joe
-----------------------------------------------------
Eric Pugh | Principal | OpenSource Connections, LLC | 434.466.1467 |
http://www.opensourceconnections.com
Free/Busy: http://tinyurl.com/eric-cal