How can I make my JUnit tests run in random order? -
i have classical structure tests, have test suite of different suites databasetests, unittests etc. suites contains other suites slowdatabasetests, fastdatabasetests etc.
what want randomize running order of tests make sure not dependent each other. randomization should @ every level, suite should shuffle test class order, , test class should shuffle test method order.
if possible in eclipse best.
you have sortable can't see how use it.
you extend blockjunit4classrunner , have computetestmethods() return randomized copy of super.computetestmethods(). use @runwith set runner use.
e.g.
package com.stackoverflow.mlk; import java.util.collections; import org.junit.runners.blockjunit4classrunner; import org.junit.runners.model.initializationerror; public class randomblockjunit4classrunner extends blockjunit4classrunner { public randomblockjunit4classrunner(class<?> klass) throws initializationerror { super(klass); } protected java.util.list<org.junit.runners.model.frameworkmethod> computetestmethods() { java.util.list<org.junit.runners.model.frameworkmethod> methods = super.computetestmethods(); collections.shuffle(methods); return methods; } } then
@runwith(com.stackoverflow.mlk.randomblockjunit4classrunner.class) public class randomorder { @test public void one() { } @test public void two() { } @test public void three() { } }
Comments
Post a Comment