Test Automation for NoSQL Databases

4,789 views
4,450 views

Published on

NoSQL Unit & Travis CI - Test automation for NoSQL databases

Published in: Technology, Education
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,789
On SlideShare
0
From Embeds
0
Number of Embeds
1,440
Actions
Shares
0
Downloads
19
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Test Automation for NoSQL Databases

  1. 1. codecentric AG 1 NoSQL Unit & Travis CI Test Automation for NoSQL Databases Tobias.Trelle@codecentric.de @tobiastrelle
  2. 2. codecentric AG 2 Tobias Trelle Senior IT Consultant @ codecentric AG Organizer of MongoDB User Group Düsseldorf Author of „MongoDB – Ein praktischer Einstieg“ (dpunkt-Verlag)
  3. 3. codecentric AG 3 Agenda Unit Testing NoSQL Unit  Travis CI
  4. 4. codecentric AG 4 Unit Testing Your Persistence Layer UI Layer Database Business Layer Persistence Layer DAO / Repository Production
  5. 5. codecentric AG 5 Unit Testing Your Persistence Layer UI Layer Database Business Layer Persistence Layer DAO / Repository Production UI Layer Embedded Database Business Layer Persistence Layer DAO / Repository Unit Test Unit Test In Process
  6. 6. codecentric AG 6 Unit Testing Your Persistence Layer Unit tests should …  be fast  run in isolation  load test data  compare data
  7. 7. codecentric AG 7 NoSQL Unit Github - https://github.com/lordofthejars/nosql-unit
  8. 8. codecentric AG 8 NoSQL Unit > Overview Benefits  Database Lifecycle Management  Connection Management  Load Test Data  Compare Data
  9. 9. codecentric AG 9 NoSQL Unit > Overview How does it work?  JUnit Extension  JUnit Rules  Annotations
  10. 10. codecentric AG 10 NoSQL Unit > Database Management Options DatabaseNoSQL Unit Embedded JVM Local Machine Database Database Remote Machine Managed Remote
  11. 11. codecentric AG 11 NoSQL Unit > Supported Databases Database Type Impl Language Embedded Managed / Remote Cassandra Column Java   CouchDB Document Erlang ---  Elasticsearch Document Java   HBase Column Java   Infinispan In Memory Java   MongoDB Document C++ fongo Mock  Neo4j Graph Java   Redis Key/Value C/C++ NoSQL Unit Mock 
  12. 12. codecentric AG 12 NoSQL Unit > Lifecycle NoSQL Unit Database Test Case Loop over tests Launch (optional) Connect to Load Test Data (optional) Compare Data Sets (optional) Shutdown (optional) Run Test Interact with
  13. 13. codecentric AG 13 NoSQL Unit > Redis Example public class EmbeddedRedisTest { @ClassRule public static EmbeddedRedis embeddedRedis = newEmbeddedRedisRule().build(); @Rule public RedisRule redisRule = newRedisRule().defaultEmbeddedRedis(); /** Unit under test. */ private KeyValueRepository repository; @Test @UsingDataSet( loadStrategy = LoadStrategyEnum.DELETE_ALL ) @ShouldMatchDataSet( location="keyvalue.json" ) public void should_insert_string() { // given KeyValueRepository repo = new KeyValueRepository( getJedisInstance() ); // when repo.setValue("hello", "redis"); // then: should match data } } Create embedded instance once for all tests Get connection once per test Prepare data Compare given and expected data after test
  14. 14. codecentric AG 14 NoSQL Unit > Redis Example > keyvalue.json { "data": [ {"simple": [ { "key":"hello", "value":"redis"} ] } ] }
  15. 15. codecentric AG 15 NoSQL Unit > MongoDB Example public class RemoteMongoDBTest { @Rule // use already running "remote" instance public MongoDbRule mongoRule = new MongoDbRule( mongoDb().databaseName("test").host("localhost").port(27017) .build() ); /** Unit under test. */ private OrderRepository repository; @Test @UsingDataSet(locations = "orders.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT) public void should_find_all_orders() { // given repository = createOrderRepository(); // when List<DBObject> orders = repository.findAll(); // then assertThat(orders, notNullValue()); assertThat(orders.size(), is(2)); } Load test data from JSON file
  16. 16. codecentric AG 16 NoSQL Unit > MongoDB Example > orders.json { "orders": [ { "type": 4711, "desc": "1st order" }, { "type": 42, "desc": "2nd order" } ] }
  17. 17. codecentric AG 17 NoSQL Unit > MongoDB > Advanced Features NoSQL Unit MongoDB supports  Replica Sets  Sharded Environments  Sharded Env. + Replica Sets …in managed mode.
  18. 18. codecentric AG 18 Travis CI http://www.travis-ci.org
  19. 19. codecentric AG 19 Travis CI > Overview Free Continuous Integration Platform: Lanuguages:  C/C++  Closure  Erlang  Go  Groovy  Java  JavaScript / Node.js  Objective-C  Ruby  Scala  … Services:  MySQL  PostgreSQL  MongoDB  CouchDB  Redis  Riak  RabbitMQ  Memcached  Cassandra  Neo4j  …
  20. 20. codecentric AG 20 Travis CI > Lifecycle Travis CI Database GitHubTests start services shutdown services clone / checkout build & run use .travis.yml: language: java services: - mongodb - redis
  21. 21. codecentric AG 21 Travis CI > Demo
  22. 22. codecentric AG 22 Travis CI > Demo
  23. 23. codecentric AG 23 Travis CI > Demo
  24. 24. codecentric AG 24 Online Resources NoSQL Unit https://github.com/lordofthejars/nosql-unit Travis CI https://travis-ci.org/ NoSQL Unit Examples https://github.com/ttrelle/nosqlunit-examples
  25. 25. codecentric AG 25 MongoDB User Group Düsseldorf https://www.xing.com/net/mongodb-dus/ http://www.meetup.com/Dusseldorf-MongoDB-User-Group/ @MongoDUS Meetup #10: MongoDB at LUMsearch.com (by Christian Douven) 03.07.2014, 19:00
  26. 26. codecentric AG 26 QUESTIONS? Tobias Trelle codecentric AG Merscheider Str. 1 42699 Solingen tel +49 (0) 212.233628.47 fax +49 (0) 212.233628.79 mail Tobias.Trelle@codecentric.de twitter @tobiastrelle www.codecentric.de blog.codecentric.de/en/author/tobias-trelle www.xing.com/net/mongodb-dus

×