java - Is there a way to override JUnit to send a response back to another method? -


is there way create junit test returns value method? realize should void return type, hoping have method - via jmeter, automatically run test before returning json string jmeter.

    @requestmapping(value = "/testgetplayer", produces = "application/json",         method = requestmethod.post) @responsebody public response getplayer(final httpservletrequest req){     this.response = new response();     string newplayer = req.getparameter("player");     this.response = pserv.checkplayer(newplayer);         if(this.testgetplayer()){         system.out.println("woohoo");     }     //assert incoming response string      //contain "created player" or somesuch           return response; }   @test public void testgetplayer(){     for(string m : response.getmessages()){         if(m.equals("pls_m001: player not exist")){             asserttrue(m.equals("pls_m001: player not exist"));         }         else{             asserttrue(m.equals("pls_m002: player exists"));         }     } } 

i want instead have this:

    @test public boolean testgetplayer(){             boolean allgood = false;      for(string m : response.getmessages()){         if(m.equals("pls_m001: player not exist")){             asserttrue(m.equals("pls_m001: player not exist"));                             allgood = true;         }         else{             asserttrue(m.equals("pls_m002: player exists"));                             allgood = true;         }     }             return allgood; } 

sorry if obvious no-no, still learning both junit , jmeter , want see how far can push them.

thanks

asserts should used show failed test, based on expectations. test should expect outcome, ideally current test become two:

testgetplayersucceeds() (asserts player exists after call) testgetplayerfails()    (asserts player not exist after call) 

usually there no point continuing test after assertion throws, except assert other conditions, in unknown state , test has failed.

however, there reasons things differently sometimes, so...

junit test methods void, not appropriate change signature. idea framework runs them you, no return type necessary. if don't need use junit framework can remove annotations , call tests whatever want.

i assume trying build test suite, calling junit test methods, , need act on outcome of previous test...

the assertion type of exception can catch in calling method, set flag (or act accordingly), rethrow assertion.

boolean allgood = false; try {     testgetplayer() } catch (assertionerror a) {     if (a.getmessage == "pls_m002: player exists") allgood = true;     throw(a); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -