Giter Site home page Giter Site logo

mockit's Introduction

MockIt: Mock-Ups in a Distributed Environment

MockIt is an open source mock up framework for Scala and Java originally written by Paul Heymann. It was released in October 2015.

A mock-up simulates the behaviour of a certain interface or module without actually implementing it. It is used for unit tests, during the development of complex software projects or prototyping.

MockIt itself is a framework to mock services or clients in a distributed environment and to simulate some of the familiar problems accompanied with distribution in a network like:

  • message transmission delay
  • message loss
  • message duplication
  • ...

Therefore it runs the mock instances as threads on the local machine or as stand alone services on remote machines. By now the following protocols are supported:

  • tcp
  • udp
  • http

MockIt provides an easy to use interface to create, run and manage the mocks from within your code.

Full Documentation

See the Wiki for full documentation, examples, guide lines and other information.

Contact

There is a Google Group where you can ask questions.

Project Structure

The structure of this project is follows:

  • mockit: sources and tests of the core library
  • mockit-java-api: sources and tests of the Java interface
  • mockit-daemon: stand alone application running the MockIt Agent
  • mockit-tool: command line tool to manage the daemons
  • demos: a collection of demo projects
  • images: images for the Wiki

Binaries

Releases

If you want to have the Jar-files directly just download them from the the release page. There your get the core library, the command line tool and the daemon application.

SBT

To integrate MockIt into your SBT project just add it as dependency to your build file:

lazy val scalaVersion = "2.11"

"com.github.pheymann" % s"mockit_$scalaVersion" % "x.y.z"

Replace the x.y.z with the correct version number you want to use (current: 0.2.0-beta).

Maven

To integrate MockIt into your Maven project just add it as dependency to your POM:

<dependency>
    <groupId>com.github.pheymann</groupId>
    <artifactId>mockit</artifactId>
    <version>x.y.z</version>
</dependency>

If you programming in Java you will need the Java API too:

<dependency>
    <groupId>com.github.pheymann</groupId>
    <artifactId>mockitjavaapi</artifactId>
    <version>x.y.z</version>
</dependency>

Replace the x.y.z with the correct version number you want to use (current: 0.2.0-beta).

Small Example: Hello World

If you want to run one or several mock-ups on different machines you have to start MockIt Daemons with the MockIt Tool on this machines (description). The number of daemons has to be at least the number of mock-ups you want to run.

Otherwise if you use the library und create your own stand alone mock-up (example) daemons are not necessary at all.

This example shows how to create a small HTTP server:

class HttpUnit extends HttpServerMockUnit {

    override def init: Unit = {
        // add a request-response pair
        add(
            HttpRequest(Get, "/webapp/test"),
            HttpResponse(OK)                        +
                ("this is a key", "and the value")  ++
                ("text/plain", "hello world".getBytes("UTF-8"))
        )
    }

}

This is the Mock Unit which implements the servers behaviour. In this example the server just sends the response hello world when a call on localhost:8080/webapp/test appears.

To run the server just call:

def main(args: Array[String]): Unit = {
    val unit = classOf[HttpUnit]

    // configure the server
    val container = new MockUnitContainer(
        unit.getCanonicalName,
        unit,
        new ServerConfiguration(
            8080,
            1,
            ConnectionType.http
        )
    )

    val shutdown = new ShutdownLatch
    val latch = new ShutdownLatch

    // run the mock in the local process
    MockIt.mockLocal(container :: Nil, shutdown, latch).call
}

The server will run in the current process as a thread and stops when the parent process stops.

For more examples take a look here

Build

If you want to build your own jar files from the raw source code just download the code from GitHub:

git clone git@https://github.com/MockIt

and for the core library run:

$ cd MockIt/mockit
$ sbt package

for the Java API:

$ cd MockIt/mockit-java-api
$ mvn clean package

for the daemon application:

$ cd MockIt/mockit-daemon
$ sbt assembly

and for the command line tool:

$ cd MockIt/mockit-tool
$ sbt assembly

Development Guide

This project is written in Scala and maintains interfaces for Java. If you want to contribute to the project you should keep the following rules and principles in mind:

  • DRY (don't repeat your self),
  • refactore the code if it is necessary,
  • write your code like a book, easy to read and understandable and use comments when necessary,
  • cover every new functionality directly or indirectly with in a unit test,
  • keep all available unit tests running,
  • do not push faulty code into the repository,
  • no IDE files in the repository.

For further information have a look into the extended guide.

Licence

This project is licensed under the MIT Licence.

External Projects

This projects are integrated into MockIt:

mockit's People

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.