Git Product home page Git Product logo

momei-mongodb's Introduction

Momei MongoDB

The primary goal of the Momei-MongoDB project is to make it easier and flexible and efficient to prepare test data before running test and clean up test data after running test in a application using MongoDB as data store.

This test framework uses mongo scripts written in javascript language to prepare and clean up, and let you utilize all the MongoDB enhancements to javascript. It's quick and easy to get started.

Get started

  1. Write a test extending the MongoAwareBaseTest class:
@TestData
public class BooksRepoTest extends MongoAwareBaseTest {

    @Test
    @TestData
    public void findBooks() {
        logger.info("Test find logic!");
    }

}
  1. Annotate you test with the annotation @TestData. If @TestData presents on a test class, the framework will read a javascript file named {test class name}.js which locates in the same directory with the test class. In this example, the BooksRepoTest.js will be read.

  2. Annotate test method with the annotation @TestData. If @TestData presents on a test method, the framework will execute the preparing javascript function named prepare4_{test method name} before test method is invoked and the cleaning javascript function named cleanup4_{test method name} after test method is invoked. The two javascript functions sit in the {test class name}.js file. In this example, BooksRepoTest.js is as follows:

// Prepare test data for test method 'findBooks'
prepare4_findBooks = function() {
    for (var i = 1; i <= 100; i++) {
        db.books.insert({ _id: ObjectId(), name: ("Thinking in Java "+i) });
    }
}

// Clean up test data for test method 'findBooks'
cleanup4_findBooks = function() {
    db.books.remove({ name: { $regex: /Thinking in Java/ } });
}

The function definition must be as follows:

<prepare4_|cleanup4_>{test method name} = function() {
    // preparing or cleaning up logic
}
  1. Lastly configure the MongoDB. Go to the class path root direction, and new a file named mongo.properties:
# mongo.host and mongo.port are optional.
# If not given, host and port default to localhost and 27017 respectively
#mongo.host=localhost
#mongo.port=27017

# mongo.db required
mongo.db=test

That's all!

momei-mongodb's People

Contributors

ikonglong avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.