GenerateTestCases, plugin to generate test methods from descriptive behaviours

Hi, I would like to receive your opinion about a plugin I'm developing that makes it really easy to create and maintain unit testing methods, so it generates them automatically from your production code (with a little help).

For example if you have a method like this one:


public class Calculator {



    /**
     *
     * @param a
     * @param b
     * @return
     * @should divide a between b
     * @should throw IllegalArgumentException if the second argument is 0
     *
     */
    double divide(double a, double b) {
        if (b == 0) {
            throw new IllegalArgumentException();
        }
        return a/b;
    }

}



It will create two test methods (for defined behaviour in bold, @should javadoc tag) like this

public class CalculatorTest {
    /**
     * @verifies divide a between b
     * @see Calculator#divide(double, double)
     */
    @Test
    public void divide_shouldDivideABetweenB() throws Exception {
        //TODO auto-generated
        Assert.fail("Not yet implemented");
    }

    /**
     * @verifies throw IllegalArgumentException if the second argument is 0
     * @see Calculator#divide(double, double)
     */
    @Test
    public void divide_shouldThrowIllegalArgumentExceptionIfTheSecondArgumentIs0() throws Exception {
        //TODO auto-generated
        Assert.fail("Not yet implemented");
    }
}


Then you just have to implement them like this, and done. You don't have to think about create test methods, just about the behaviour your production methods has to comply

public class CalculatorTest{


    /**
     * This is the generated method for testing the behaviour
     *
     * @verifies divide a between b
     * @see Calculator#divide(double, double)
     */
    @Test
    public void divide_shouldDivideABetweenB() throws Exception {

        Calculator calculator = new Calculator();
        // so we test
        double actualValue = calculator.divide(4, 2);

        assertThat(actualValue, Is.is(2.0));

    }

    /**
     * @verifies throw IllegalArgumentException if the second argument is 0
     * @see Calculator#divide(double, double)
     */
    @Test(expected = IllegalArgumentException.class)
    public void divide_shouldThrowIllegalArgumentExceptionIfTheSecondArgumentIs0() throws Exception {


        Calculator calculator = new Calculator();

        double actualValue = calculator.divide(4, 0);// 0 is not allowed

    }
}


Now it has support for:

- Jumping from the custom @should tag to test method with CTRL + Click
- Renaming @should content so you can refine your behaviour description
- Junit 3 and Junit 4 style generated test methods
- Inspection and Intention to create missing test methods

Coming...

- Automatic full renaming support

Please take yourself ten minutes to see this video

http://www.youtube.com/watch?v=WYET6PECxuc

, and for sure you will find it very helpful for reducing the time you take to create unit test methods.

I'm open to hear you opinions, thank you very much :D

Oh, by the way, you can install it right from IntelliJ, just look for GenerateTestCases from Settings > Plugins, or download it from here http://plugins.intellij.net/plugin/?idea&id=5847

Please sign in to leave a comment.