Git Product home page Git Product logo

ndeepsubrogate's Introduction

NDeepSubrogate

DeepSubrogate is integration testing framework (.NET), which goes hand in hand with dependecy injection/IoC containers, for substituting objects in an object graph. Objects are substituted, using predefined rules, with objects called Surrogates that may be Mocks or Spies. The verb used to refer replacing one object with another is to subrogate. As objects might be replaced very deep within an object graph, we called this process deep subrogate. When done, the original objects can be restored back leaving the object graph in its original state.

An object graph is specified with an initial object that belongs to the graph. The graph is traversed starting from that initial object replacing the desired objects with the corresponding surrogate.

General Idea

Normally, when doing unit tests, let us say with NUnit, we have a test suite class that contain all the test methods that make assertions on the expected object's behavior. Such test suite class instance, TS, contains a reference to an object whose behavior we want to test. Let us call it A. Now, A uses another object of class B to implement its logic. This gives the following object graph, starting from TS:

ObjGraph

When testing A, we might want to mock B to test A's behavior regardless of B's original definition. Therefore, we replace B for a surrogate, B'.

$$B' = subrogate(B)$$

The object graph now becomes

ObjGraph

Once we are done with testing, the object graph can be restored back to its original state. DeepSubrogate remembers all the replacements and can take us back to the state before substitution. This is to make sure the rest of the tests that assume the original object graph state are not affected. As a result, in this example, DeepSubrogate would restore B so the object graph is back to

ObjGraph

Sample code (C#)

//TODO: Add C# example

Current state of development

Right now, the following Dependency Injection (DI)/Inversion of Control (IoC) containers are supported:

The following DI containers are planned to be supported in the near future:

The mock/fakes framework used is FakeItEasy. Others might be easily integrated.

Although you might use NDeepSubrogate with any test framework, right now there is direct integration with NUnit. Support for xUnit might be added in the near future.

Graphviz DOT for images

  • Original object graph
digraph {
    rankdir = LR;
    TS -> A -> B
}
  • Subrogated object graph
digraph {
    rankdir = LR;
    "B'" [color=red fontcolor=red];
    TS -> A -> "B'"
}

ndeepsubrogate's People

Contributors

rodyce 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.