GithubHelp home page GithubHelp logo

dut3062796s / jukito Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arcbees/jukito

0.0 2.0 0.0 540 KB

The combined power of JUnit, Guice and Mockito. Plus it sounds like a cool martial art.

Home Page: http://jukito.arcbees.com/

License: Other

Java 100.00%

jukito's Introduction

![Jukito] (http://i.imgur.com/rSeHAEc.png "Jukito")

###The combined power of JUnit, Guice and Mockito. Plus it sounds like a cool martial art.


So you started using dependency injection because somebody told you it would make your tests simpler? But as you gaze at your deep hierarchy of test classes, "simple" is not exactly the word you think of. Plus, creating a new mock whenever you add a parameter to an injected constructor gets old very quickly.

You are not alone! And Jukito was created specifically for people like you. Read on, or get started right away!

If you use Google Guice, or if your GWT application uses Gin, then Jukito is the perfect antidote to your unit testing headaches. Now you can write tests like this:

@RunWith(JukitoRunner.class)
public class EmailSystemTest {

  @Inject EmailSystemImpl emailSystem;
  Email dummyEmail;

  @Before
  public void setupMocks(
      IncomingEmails incomingEmails,
      EmailFactory factory) {
    dummyEmail = factory.createDummy();
    when(incomingEmails.count()).thenReturn(1);
    when(incomingEmails.get(0)).thenReturn(dummyEmail);
  }

  @Test
  public void shouldFetchEmailWhenStarting(
      EmailView emailView) {
    // WHEN
    emailSystem.start();

    // THEN
    verify(emailView).addEmail(dummyEmail);
  }
}

That's right, Jukito lets you @Inject fields exactly as if your test class was injected with Guice. You can also inject parameters into your @Test, @Before and @After methods. Guice's just-in-time binding automatically instantiate your concrete classes, like EmailFactory. What about interfaces like IncomingEmails or EmailView? Jukito mocks them out automatically for you using mockito!

Let's look at another example:

@RunWith(JukitoRunner.class)
public class CalculatorTest {

  public static class Module extends JukitoModule {
    protected void configureTest() {
      bindMany(Calculator.class,
          ScientificCalculator.class,
          BusinessCalculator.class);

      bindManyInstances(AdditionExample.class, 
          new AdditionExample(1, 1, 2),
          new AdditionExample(10, 10, 20),
          new AdditionExample(18, 24, 42));
    }
  }

  @Test
  public void testAdd(@All Calculator calculator, @All AdditionExample example) {
    // WHEN
    int result = calculator.add(example.a, example.b);

    // THEN
    assertEquals(example.expected, result);
  }
}

As you see here, Jukito lets you define your very own test module, where you can bind classes just like a regular Guice module. It doesn't stop there, however. The bindMany methods let you bind different classes or instances to the same interface. Combined with the powerful @All annotation this lets you easily run a single test on a whole suite of test examples. The code above will run a total of six tests!

##Getting Started Read the wiki to find out everything Jukito has to offer, and join the discussion!

##Latest Release

  • 1.5

##Links

##Thanks to Arcbees.com

Atlassian

IntelliJ

jukito's People

Contributors

ahri avatar aldenquimby avatar branflake2267 avatar chris-v avatar christiangoudreau avatar diamondq avatar durron597 avatar jclariviere avatar meriouma avatar olafleur avatar philbeaudoin avatar przemekgalazka avatar yln 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.