单元测试 NoSQLUnit 0.4.1 发布,增加 Redis 的支持
jopen 12年前
<p><a href="/misc/goto?guid=4958346678297125590" target="_blank"><em>NoSQLUnit</em> </a>是一个 <em>JUnit</em> 的扩展,用来为那些使用了 NoSQL 后端的应用提供单元测试和集成测试的工具。<br /> NoSQLUnit 0.4.1 发布,该版本最主要是增加对 Redis 的测试支持。测试示例代码请看 WhenYouFindABook.java<br /> </p> <pre class="brush:java; toolbar: true; auto-links: false;">import static com.lordofthejars.nosqlunit.redis.RedisRule.RedisRuleBuilder.newRedisRule; import static com.lordofthejars.nosqlunit.redis.ManagedRedis.ManagedRedisRuleBuilder.newManagedRedisRule; import static org.junit.Assert.assertThat; import static org.hamcrest.CoreMatchers.is; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import redis.clients.jedis.Jedis; import com.lordofthejars.nosqlunit.annotation.UsingDataSet; import com.lordofthejars.nosqlunit.core.LoadStrategyEnum; import com.lordofthejars.nosqlunit.demo.model.Book; import com.lordofthejars.nosqlunit.redis.ManagedRedis; import com.lordofthejars.nosqlunit.redis.RedisRule; public class WhenYouFindABook { static { System.setProperty("REDIS_HOME", "/opt/redis-2.4.16"); } @ClassRule public static ManagedRedis managedRedis = newManagedRedisRule().build(); @Rule public RedisRule redisRule = newRedisRule().defaultManagedRedis(); @Test @UsingDataSet(locations="book.json", loadStrategy=LoadStrategyEnum.CLEAN_INSERT) public void book_should_be_returned_if_title_is_in_database() { BookManager bookManager = new BookManager(new Jedis("localhost")); Book findBook = bookManager.findBookByTitle("The Hobbit"); assertThat(findBook, is(new Book("The Hobbit", 293))); } }</pre> <p></p> <p><em><br /> </em></p>