Skip to content
Zachary Lindberg edited this page Feb 23, 2015 · 5 revisions

Welcome to the JANUS wiki!

People often forget that object oriented programming is just as much about the ways in which objects talk to each other as the objects themselves! It’s usually pretty easy to define and codify the objects in our domain - but how do we enforce their patterns of communication? Well, at least in a language like Java, we get a pretty good tool for doing that - interfaces! Often times, however, this isn’t enough. While java interfaces allow us to specify a common set of method signatures, how do we ensure the objects implementing them agree and conform to how to handle edge and special cases. Might calling bubbleify() with a null argument on one object return the empty string, while calling it the same way on an object of a different implementing class cause it to return null? If we want our object communication protocols to be air tight we need a way to ensure that they exhibit correct behavior which simple methods signatures cannot capture.

JANUS to the rescue!

Janus helps you test that all implementations of an interface in your project are fulfilling their proper contracts by 1) finding all the implementers of an interface in your project, 2) instantiating those classes in every way possible, and 3) running tests which help define the behavior of that interface on all of those possible instances.

To run Janus:

  • Create a test class for your interface
  • Set the base package you would like Janus to search
  • Mark your interface as @UnderTest
  • Set your test to @RunWith(Janus.class)
@RunWith(Janus.class) 
@JanusOptions(
        basePackage = "org.janvs.samples"
)
public class BubblableTest {

    @UnderTest
    private Bubblable bubble;

    @Test
    public void shouldAdd() {
        String string = bubble.bubblify("bubble");
        assertNotNull(string);
    }
}
Clone this wiki locally