Run TestCase from java and display results on Eclipse JUnit view -


i defined classes with, each one, several public methods @test annotation. methods follow same behavioral pattern (retrieve ressources ids, test if empty, log, call real test each line on resource). so, i've externalized behavior in abstract class instanciate on each method, this:

@test public void sometest(){   new basictestpattern("x","y","z"){ // parameters retrieve resources      @override      protected void testline(){          somecheck1();         somecheck2();      }   }.run(); } 

this solution eliminate 10-30 lines per test method. now, want go further custom annotation, that:

@testpattern(param1="x",param2="y",param3="z") public void sometest(){   somecheck1();   somecheck2(); } 

finally created little framework retrieve methods new annotation in order instanciate basictestpattern , execute it. executed in testcase subclass, that:

testcase junit_test = new testcase(){   @override   public void runtest() {     pattern.run();   } };  junit_test.run(); 

however, no test displayed/listed in junit view eclipse. see number of tests succeeded. how can ? thank you.

you need make own custom runner find methods annotated @testpattern method. (and @test ?)

then test class this:

@runwith(yourrunner.class) public class yourtest{     @testpattern(param1="x",param2="y",param3="z")    public void sometest(){         ...    }     @test    public void anothernormaltest(){         ...    }   } 

this blog explains how write custom runners. can away extending blockjunit4classrunner add special test methods list of tests run.

i think have override computetestmethods() method how blockjunit4classrunner finds test methods run (the methods annotated @test) can override find methods annotated own annotation.

  public class testrunner extends blockjunit4classrunner{    protected list<frameworkmethod> computetestmethods() {         //this @test annotated methods         list<frameworkmethod> testannotatedmethods = super.computetestmethods();         //these methods @testpattern annotation         list<frameworkmethod> yourannotatedmethods = gettestclass().getannotatedmethods(testpattern.class);          //do whatever need generate test          //methods correct parameters based on          //the annotation ?           //might need make fake or          //synthetic frameworkmethod instances?         ...         //combine everyting single list        list<frameworkmethod> alltestmethods =...        //finally return frameworkmethods single list        return alltestmethods;  }  } 

you might have make own frameworkmethod implementation wrapper info annotation , whatever set required before invoking method.

this make seamlessly integrate normal junit classes , work junit ide view

good luck


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -