is there annotation or other convenient way ignore junit tests specific android sdk versions? there similar lint annotation targetapi(x)? or manually have check whether run test using build.version?
i don't think there ready pretty easy create custom annotation this.
create custom annotation
@target( elementtype.method ) @retention( retentionpolicy.runtime) public @interface targetapi { int value(); }
ovverride test runner (that check value , ignore/fire test)
public class conditionaltestrunner extends blockjunit4classrunner { public conditionaltestrunner(class klass) throws initializationerror { super(klass); } @override public void runchild(frameworkmethod method, runnotifier notifier) { targetapi condition = method.getannotation(targetapi.class); if(condition.value() > 10) { notifier.firetestignored(describechild(method)); } else { super.runchild(method, notifier); } } }
and mark tests
@runwith(conditionaltestrunner.class) public class testclass { @test @targetapi(6) public void testmethodthatrunsconditionally() { system.out.print("test me!"); } }
just tested, works me. :)
credits to: conditionally ignoring junit tests
Comments
Post a Comment