JUnit primer

 

This section is a quick and admittedly incomplete introduction to JUnit. We’ll provide the basics needed to understand our code examples. First, JUnit test cases extend junit.framework.TestCase. Our concrete test classes adhere to a naming convention: we suffix class names with Test. For example, our QueryParser tests are in QueryParserTest.java.

JUnit automatically executes all methods with the signature public void test-XXX(), where XXX is an arbitrary but meaningful name. JUnit test methods should be concise and clear, keeping good software design in mind (such as not repeating yourself, creating reusable functionality, and so on).

Assertions

JUnit is built around a set of assert statements, freeing you to code tests clearly and letting the JUnit framework handle failed assumptions and reporting the details. The most frequently used assert statement is assertEquals; there are a number of overloaded variants of the assertEquals method signature for various data types. An example test method looks like this:

public void testExample()  {
 SomeObject obj = new SomeObject();
 assertEquals(10,  obj.someMethod());
}

JUnit in context

Testing Lucene

Mock objects

About the Authors

Part 1. Core Lucene

Chapter 1. Meet Lucene

1.1. Dealing with information explosion

1.2. What is Lucene?

1.3. Lucene and the components of a search application

1.4. Lucene in action: a sample application

1.5. Understanding the core indexing classes

1.6. Understanding the core searching classes

1.7. Summary

Chapter 2. Building a search index

2.1. How Lucene models content

2.2. Understanding the indexing process

2.3. Basic index operations

2.4. Field options

2.5. Boosting documents and fields

2.6. Indexing numbers, dates, and times

2.7. Field truncation

2.8. Near-real-time search

2.9. Optimizing an index

2.10. Other directory implementations

2.11. Concurrency, thread safety, and locking issues

2.12. Debugging indexing

2.13. Advanced indexing concepts

2.14. Summary

Chapter 3. Adding search to your application

3.1. Implementing a simple search feature

3.2. Using IndexSearcher

3.3. Understanding Lucene scoring

3.4. Lucene’s diverse queries

3.5. Parsing query expressions: QueryParser

3.6. Summary

Chapter 4. Lucene’s analysis process

4.1. Using analyzers

4.2. What’s inside an analyzer?

4.4. Sounds-like querying