Wednesday, November 9, 2011

Convert existing junit 4 testcases into perf tests in 2 minutes

1.

Have junitperf jar in your compile and runtime classpath http://www.clarkware.com/software/junitperf-1.9.1.zip

2.
add following code in a main method in ur junit class
public static void main(..) { int users = 4; int iterations = 5; JUnit4TestAdapter testCase = new JUnit4TestAdapter(MyOwnJunit.class); junit.framework.Test loadTest = new LoadTest(testCase, users, iterations); junit.textui.TestRunner.run(loadTest); }

3.

run junit as java program instead of junit
similar decorators can be used for performance testing just as for multi-threaded testing. This can be huge time saver to quickly test any code for concurrent access issues, that get reported. You can make these concurrent access unit tests as part of your CI as well.

No comments: