Wednesday, 15 April 2015

java - what is the best practice to determine the execution time of the bussiness relevant code of my junit? -



java - what is the best practice to determine the execution time of the bussiness relevant code of my junit? -

the test execution time displayed in eclispse->junit-view depends on whole test case execution includes:

testdata preperation executing businesslogic assert results

i need more detailed statement execution time of businesslogic , businesslogic. have done within testcase:

date lnow = new date(); list<geo> lallbasisgeo = mgeoevaluator.evaluateallgeo(lgeofixture.getgeo(), lallgeo); date lstop = new date(); system.out.println("time of execution in seconds:"+((lstop.gettime()-lnow.gettime())/1000));

well... think determine time in realy awkward way. furthermore dont think necessary declare 2 date variables.

i need advice writing code more efficiently...

in unit test prefer add together timeout test junit 4 annotation, determine whether test passes (fast enough) or not:

@test(timeout=100)//let test fail after 100 milliseconds public void infinity() { while(true); }

to determine exact runtime of business logic add together time statements right before , after critical codepath did, repeat several times scholastically right results, , remove statements again, slim code.

long start = system.currenttimemillis(); //execute logic in between long end = system.currenttimemillis(); system.out.println("debug: logic toke " + end - start + " milliseconds");

java junit

No comments:

Post a Comment