nosewheelie

Technology, mountain biking, politics & music.

Instinct 0.1.0

with 7 comments

One of the benefits of working as a consultant is that there are occasional downtimes between gigs. The beauty of these is you get to spend some time learning new stuff or working on interesting projects. I’ve been lucky enough to have spent the last couple of weeks working on my latest pet project, a behaviour driven development (BDD) framework called Instinct. Now that my little proof-of-concept now has enough features to be released, I’m announcing it here and on the Instinct discussion list.

So what is it?

From the source:

Instinct is a Behaviour Driven Development (BDD) framework for Java. Inspired by RSpec, Instinct provides flexible annotation of contexts, specifications, mocks, etc. (via Java 1.5 annotations, marker interfaces or naming conventions); automatic creation of test doubles (dummies, mocks & stubs) & test subjects; a verification API (similar to JUnit’s Assert); and JUnit test runner integration.

What! Another testing framework

While Instinct isn’t intended as a “testing” framework, it can indeed be used as a testing framework in place of JUnit, TestNG, JTiger, etc. Instinct was developed to be used in performing behaviour driven development, which has a slightly different emphasis than testing, focusing more on specifying behaviour and exploring the design of code. I won’t go into the psychology of why names are important, suffice to say that a new framework allows me to explore behaviour driven development (which the projects I’ve been working on have been doing for a while) while also offering additional features not found in current testing frameworks.

Also, Instinct was developed to overcome some deficiencies in current frameworks and provide a simplification of key ideas such as mocking. I also wanted to be able to standardise on names of common items used in testing (subject, fixture, mock, stub, dummy, etc.), and provide framework level support for these items.

Instinct will also offer flexibility in the way things are marked, and hence made available to the framework. TestNG pioneered the use of annotations for marking tests and providing metadata (such as test groups), however there are times when you may not want to use annotations and would prefer say a naming convention (cf. JUnit picks up method names starting with “test”) or a marker interface.

My last post ended with a discussion on the problems with simplifying mock object based tests, Instinct aims to address these by providing explicit framework support.

Here’s a complete list of why I created Instinct:

  • Instinct is BDD framework, so has a slightly different focus to conventional testing frameworks.
  • It formalises definitions (by including them in the syntax of the framework) of common test objects such as subjects, mocks & stubs.
  • It Includes test objects directly into the lifecycle of a specification.
  • It does away with needless infrastructure setup such as stub/mock creation.
  • Flexible marking of test objects - specifications, mocks, stubs, dummies, etc. based on annotations, marker interfaces and naming conventions.
  • Test objects are explicitly marked with their function.
  • Simplification of mocks and controllers, the mocking API only provides access to the mock, doing away with the need to access the controller and manage two objects.
  • It removes the need for concrete class inheritance (which most testing frameworks now support anyway).
  • It makes use of Java 1.5 features in order to simplify testing, such as annotations and typesafe mock creation.
  • It embodies lots of common code usually created on TDD projects as Open Source Software making it available outside individual projects.
  • I wanted to explore the state vs. interaction testing debate.
  • Other Java BDD frameworks (such as jBehave) have a different focus.

If I wanted BDD, I’d use jBehave

True, jBehave is the original BDD framework. However, jBehave’s goals and implementation is different to Instinct. jBehave appears to be aiming at a higher level (i.e. not atomic), and may even allow you to specify acceptance/functional type tests in textual form, and parsing them into executable statements. I wasn’t able to confirm any of this however as the jBehave source link is dead andemail to the maintainers has not been returned.

Update: Dan North has replied with a correct link: http://jbehave.org/.

So what do I get?

Instinct 0.1.0 provides the ability to run a behaviour context (the equivalent of a JUnit TestCase), will discover and run all specifications within that context, and will discover and run all before and after specification methods in the correct order. Contexts can only be run all at once (unless you split them across source tree) via a native Ant task or using the supplied JUnit test suite.

Specifically, 0.1.0 includes the following features:

  • Support for running behaviour contexts containing specifications (marked using Java 1.5 annotations), effectively providing a testing framework.
  • Marker annotations for specification lifecycle methods (BeforeSpecification, AfterSpecification & Specification) and grouping of specifcations (BehaviourContext).
  • An Ant task, providing aggregation of contexts and result output (similar to the JUnit Ant task).
  • An integrated mocking API, built on jMock 1.1.
  • A simple Verification class, similar to JUnit’s Assert. This will probably change in future releases, possibly to use Hamcrest matchers.
  • Support for running Instinct within an IDE is provided via a JUnit test suite (com.googlecode.instinct.integrate.junit.JUnitSuite), however this will run all contexts at once and doesn’t provide nice test names in the IDE’s test output UI (JUnit finds tests based on reflection and Class.getDeclaredMethods() cannot be proxied to provide nice names).
  • A sample project showing how to use Instinct.

What’s next?

See the roadmap for complete details, but basically:

  • An IntelliJ plugin.
  • Improvements to the verification API, possibly based on Hamcrest.
  • Completion of the auto test-double creation code.
  • Implementation of additional markers - naming conventions & marker interfaces.
  • JUnit XML test output formatters, for integration of JUnit style XSL stylesheets.

Tell me more

Check out the project home page. There is also an introductory tutorial available and the Instinct discussion list.

Written by Tom Adams

January 24th, 2007 at 2:42 pm

Posted in BDD, Instinct, Java, TDD

7 Responses to 'Instinct 0.1.0'

Subscribe to comments with RSS or TrackBack to 'Instinct 0.1.0'.

  1. Sounds very interesting. Have you looked into providing a JUnit 4 custom runner? It should give you all the flexibility you need to provide nice method names in the IDE.

    David Saff

    25 Jan 07 at 11:28 am

  2. @David: I have briefly looked into it, however I wasn’t able to get anything working in IntelliJ to my satisfaction. I’m pretty sure IntelliJ doesn’t contain full support for JUnit 4, so it may have just been an IntelliJ issue. I will take another look though.

    Tom Adams

    25 Jan 07 at 11:44 am

  3. blonde lesbian sex toy…

    Latest blonde lesbian sex toy news…

  4. upskirt in church…

    Features of upskirt in church….

  5. 1990 nissan 300zx specs…

    ha-rd-po-rn-fu-ck 1973980 1990 nissan 300zx specs friends…

  6. free credit history check…

    ka-ka-sh-ka 1973980 Modern view of free credit history check….

  7. thunder bird…

    thunder bird foundation…

    thunder bird

    8 Jun 07 at 3:43 am

Leave a Reply