It seems like you might not be calling Close on the IndexWriter/Reader/Searchers that you use while performing your tests. If you don't do that and you are using the FSDirectory class (which represents a file system), then lock files are created which prevent the opening of the indexes in the directories.
That said, make sure to call the Close method on any objects that expose one when your test is complete. Make sure to use a try/finally block to ensure that the objects are closed.
Personally I've created an extension method which takes an object and returns an IDisposable implementation which will call Close when Dispose is called, allowing it to be used in using statements (I use reflection on the type to get the Close method and then I generate a lambda expression which is called in the Dispose method).
Also, if you are running a test harness and you are opening and closing the indexes in your text fixtures you either have to make sure that:
- The tests that access the indexes are run synchronously so they don't try to open locked directories
OR
- Have one test class for all search-related tests and handle the opening and closing of the indexes in whatever setup and teardown mechanisms exist for your test harness. You should also do the population of your index in the setup as well (and not make it one of the test cases, otherwise, you will have synchronization problems).