views:

940

answers:

2

Hello It' possible to use Junitperf with junit4? I've a simplet Junit4 test class with several tests and i want to do a TimedTest on single test of that class. How can i do that?

To be more clear my Junit4 class is something like:

public class TestCitta {

    @Test
    public void test1 {}

        @Test
    public void test2 {}
}

with junit3 i shold write something like:

public class TestCittaPerformance {

    public static final long toleranceInMillis = 100;

    public static Test suite() {

     long maxElapsedTimeInMillis = 1000 + toleranceInMillis;

     Test testCase = new TestCitta("test2");

     Test timedTest = new TimedTest(testCase, maxElapsedTimeInMillis);

     return timedTest;
    }

    public static void main(String args[]) {
     junit.textui.TestRunner.run(suite());
    }
}

with Junit4?

+2  A: 

I had the same problem but was not lucky trying to make it run in different build environments. So I used the @Rule feature available since JUnit 4 to inject performance test invocation and requirements checking using annotations. It turned out to become a small library which replaced JUnitPerf in this project and I published it under the name ContiPerf. If you are interested in this approach, you can find it at http://databene.org/contiperf.

Volker
Nice library, i like it! :)
JavaRocky
this is a great junit4 library.
yincrash