java - I wish to run test cases based on the run mode declared in an excel -



java - I wish to run test cases based on the run mode declared in an excel -

please find below codes , query mentioned @ last.

**annotation list**

public interface annotationlist{ @documented @retention(retentionpolicy.runtime) @target(elementtype.type) public @interface qcid { string[] value(); } @documented @retention(retentionpolicy.runtime) @target(elementtype.type) public @interface author { string value(); } @documented @retention(retentionpolicy.runtime) @target(elementtype.method) public @interface order { int value(); } @documented @retention(retentionpolicy.runtime) @target(elementtype.method) public @interface mytest { static class none extends throwable { private static final long serialversionuid = 1l; private none() { }}

junitlink

public class junitlink extends blockjunit4classrunner { // todo work in test status see if things should run. public static final logger logger = loggerfactory.getlogger(junitlink.class); public junitlink(class<?> klass) throws initializationerror { super(klass); } @override public void run(final runnotifier notifier) { junitlink.super.run(notifier); } @override protected list<frameworkmethod> computetestmethods() { list<frameworkmethod> classmethods = gettestclass().getannotatedmethods(annotationlist.mytest.class); sortedmap<integer, frameworkmethod> sortedtestmethodlist = new treemap<integer,frameworkmethod>(); (frameworkmethod seleniumtest : classmethods) { if (seleniumtest.getannotation(annotationlist.order.class) != null) { sortedtestmethodlist.put(seleniumtest.getannotation(annotationlist.order.class).value(),seleniumtest); } } homecoming new arraylist<frameworkmethod>(sortedtestmethodlist.values()); } @override protected void runchild(frameworkmethod method, runnotifier notifier) { eachtestnotifier eachnotifier = makenotifier(method, notifier); if (method.getannotation(ignore.class) != null) { runignored(eachnotifier); } else { runnotignored(method, eachnotifier); } logger.info("test {} run completed", method.getname()); } private int runnotignored(frameworkmethod method,eachtestnotifier eachnotifier) { int failures = 0; eachnotifier.fireteststarted(); seek { methodblock(method).evaluate(); } grab (assumptionviolatedexception e) { eachnotifier.addfailedassumption(e); logger.error("test {} failed!", method.getname()); failures++; } grab (throwable e) { eachnotifier.addfailure(e); logger.error("test {} failed!", method.getname()); failures++; } { eachnotifier.firetestfinished(); } homecoming failures; } private void runignored(eachtestnotifier eachnotifier) { eachnotifier.firetestignored(); } private eachtestnotifier makenotifier(frameworkmethod method,runnotifier notifier) { description description = describechild(method); homecoming new eachtestnotifier(notifier, description); }}

start test

@runwith(junitlink.class) public class startup extends selenesetestbase { public static readproperties settings = new readproperties(); public static final logger logger = loggerfactory.getlogger(inf.class); public static webdriver driver; public static actions actions; @override @before public void setup() { } @override @after public void teardown() { } @beforeclass public static void startbrowser() { //start driver etc } @afterclass public static void tearclassdown() { //kill driver } }

//test cases written these

@author("xxxx") @qcid({ "smoke_tc01", "smoke_tc02", "smoke_tc03", "tc04"}) public class smoketest extends startup{ private components component = new components(); private string testdatasheetname = "smoke"; public smoketest() throws exception { } @mytest @order(1) public void openhomepage() throws exception { component.openapp(); } @mytest @order(2) public void login() throws exception { component.login(usid, pwd); } @mytest @order(3) public void isterminallocked() throws exception { component.isterminallocked(); }

all test method runs in order. want run specific test cases have runmode "yes" declared in excel. can add together extraline before each test cases read lines excel , run particular test case want read excel , pass selected testcases(based on runmode) junit runner.

please help me.

i think question borderline "too broad". it's possible may closed reason.

have @ a junit rule conditionally ignore tests. issatisfied() have parse excel. can utilize apache poi this.

java junit junit4

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -