26
codecentric AG 1 NoSQL Unit & Travis CI Test Automation for NoSQL Databases [email protected] @tobiastrelle

Test Automation for NoSQL Databases

Embed Size (px)

DESCRIPTION

NoSQL Unit & Travis CI - Test automation for NoSQL databases

Citation preview

Page 1: Test Automation for NoSQL Databases

codecentric AG 1

NoSQL Unit & Travis CI Test Automation for NoSQL Databases

[email protected] @tobiastrelle

Page 2: Test Automation for NoSQL Databases

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)

Page 3: Test Automation for NoSQL Databases

codecentric AG 3

Agenda

Unit Testing NoSQL Unit Travis CI

Page 4: Test Automation for NoSQL Databases

codecentric AG 4

Unit Testing Your Persistence Layer

UI Layer

Database

Business Layer

Persistence Layer

DAO / Repository

Production

Page 5: Test Automation for NoSQL Databases

codecentric AG 5

Unit Testing Your Persistence Layer

UI Layer

Database

Business Layer

Persistence Layer

DAO / Repository

Production

UI Layer

EmbeddedDatabase

Business Layer

Persistence Layer

DAO / Repository

Unit Test

Unit Test

In Process

Page 6: Test Automation for NoSQL Databases

codecentric AG 6

Unit Testing Your Persistence Layer

Unit tests should …

be fast run in isolation load test data compare data

Page 7: Test Automation for NoSQL Databases

codecentric AG 7

NoSQL Unit

Github - https://github.com/lordofthejars/nosql-unit

Page 8: Test Automation for NoSQL Databases

codecentric AG 8

NoSQL Unit > Overview

Benefits

Database Lifecycle Management

Connection Management Load Test Data Compare Data

Page 9: Test Automation for NoSQL Databases

codecentric AG 9

NoSQL Unit > Overview

How does it work?

JUnit Extension JUnit Rules Annotations

Page 10: Test Automation for NoSQL Databases

codecentric AG 10

NoSQL Unit > Database Management Options

DatabaseNoSQL Unit

Embedded

JVM

Local Machine

Database

Database

Remote Machine

Managed Remote

Page 11: Test Automation for NoSQL Databases

codecentric AG 11

NoSQL Unit > Supported Databases

Database Type ImplLanguage

Embedded Managed / Remote

Cassandra Column Java ü üCouchDB Documen

tErlang --- ü

Elasticsearch

Document

Java ü üHBase Column Java ü üInfinispan In

MemoryJava ü ü

MongoDB Document

C++ fongo Mock üNeo4j Graph Java ü üRedis Key/Value C/C++ NoSQL Unit

Mockü

Page 12: Test Automation for NoSQL Databases

codecentric AG 12

NoSQL Unit > Lifecycle

NoSQL Unit Database Test Case

Loop overtests

Launch (optional)

Connect to

Load Test Data (optional)

Compare Data Sets (optional)

Shutdown (optional)

Run Test

Interact with

Page 13: Test Automation for NoSQL Databases

codecentric AG 13

NoSQL Unit > Redis Examplepublic class EmbeddedRedisTest {

@ClassRulepublic static EmbeddedRedis embeddedRedis = newEmbeddedRedisRule().build();

@Rulepublic 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

Page 14: Test Automation for NoSQL Databases

codecentric AG 14

NoSQL Unit > Redis Example > keyvalue.json

{ "data": [ {"simple": [ { "key":"hello", "value":"redis"} ]

} ]}

Page 15: Test Automation for NoSQL Databases

codecentric AG 15

NoSQL Unit > MongoDB Examplepublic class RemoteMongoDBTest {

@Rule // use already running "remote" instancepublic 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

Page 16: Test Automation for NoSQL Databases

codecentric AG 16

NoSQL Unit > MongoDB Example > orders.json

{ "orders": [ { "type": 4711, "desc": "1st order" }, { "type": 42, "desc": "2nd order" } ]}

Page 17: Test Automation for NoSQL Databases

codecentric AG 17

NoSQL Unit > MongoDB > Advanced Features

NoSQL Unit MongoDB supports

Replica Sets Sharded Environments Sharded Env. + Replica Sets

…in managed mode.

Page 18: Test Automation for NoSQL Databases

codecentric AG 18

Travis CIhttp://www.travis-ci.org

Page 19: Test Automation for NoSQL Databases

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 …

Page 20: Test Automation for NoSQL Databases

codecentric AG 20

Travis CI > Lifecycle

Travis CI Database GitHubTests

start services

shutdown services

clone / checkout

build & run use

.travis.yml:

language: javaservices: - mongodb - redis

Page 21: Test Automation for NoSQL Databases

codecentric AG 21

Travis CI > Demo

Page 22: Test Automation for NoSQL Databases

codecentric AG 22

Travis CI > Demo

Page 23: Test Automation for NoSQL Databases

codecentric AG 23

Travis CI > Demo

Page 24: Test Automation for NoSQL Databases

codecentric AG 24

Online Resources

NoSQL Unithttps://github.com/lordofthejars/nosql-unit

Travis CIhttps://travis-ci.org/

NoSQL Unit Exampleshttps://github.com/ttrelle/nosqlunit-examples

Page 25: Test Automation for NoSQL Databases

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

Page 26: Test Automation for NoSQL Databases

codecentric AG 26

QUESTIONS?

Tobias Trelle

codecentric AGMerscheider Str. 142699 Solingen

tel +49 (0) 212.233628.47fax +49 (0) 212.233628.79mail [email protected]

twitter @tobiastrelle

www.codecentric.de

blog.codecentric.de/en/author/tobias-trelle

www.xing.com/net/mongodb-dus