code coverage with gui execution and without writing test cases

balram maurya July 28, 2013

hi everyone,

i am new to clover.
i have installed clover with ant and eclipse and written test cases and i generated the code coverage report successfully .
now i want to attach clover with my web-project in eclipse and if i run with on appache server
then i want to generate code coverage how much code covered when click on any link.
and also it should be increase as i click more links.

if is it possible please give me solution ..

thanks in advance.

2 answers

1 accepted

0 votes
Answer accepted
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 28, 2013

Hi Balram,

Steps you have to perform:

1) Set the flush policy to "threaded" or "interval" (Project Properties > Clover > Flush Policy) and rebuild the whole project.

2) Create a WAR with instrumented classes and deploy to your server. Make sure that clover.jar is available on server's class path.

3) If your application server runs on the same PC as your Eclipse, then use absolute path for initstring (Project Properties > Clover > Initstring > disable "Relative to project root" and choose "custom initstring" toggle).

If not - copy clover.db (coverage.db) produced after compilation to your server and run server with -Dclover.initstring=/path/to/clover.db parameter.

4) Run your server (I guess that using "Run with Clover as..." and your run configuration in Eclipse shall be sufficient).

4) Execute your manual tests

5) Generate report as soon as tests are done. In case when server was running on a different machine, you'll have to copy coverage data files back to your PC.

More information:

Cheers
Marek

balram maurya July 28, 2013

()

i have attached the image

balram maurya July 28, 2013

thanks a lot Marek.

  • i used above configuration as shown in image.
  • my server and eclipse both are on same pc.
  • i copied clover.jar file on appache tomcat\lib folder.
  • i created war file >deployed on tomcat server> run and click on UI.


    but now i am not getting how to generate code coverage report.
    and where it will generate report.
    if i am missing somthing.. please tell me Marek.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 28, 2013

Select "Custom value" radio button. Disable the "Relative to project dir checkbox". Put an absolute path in the "Custom value" text box. Rebuild the whole project.

Coverage recording files will be written into the same directory where coverage.db is located. You shall find file(s) named like 'coverage.dbsome_hash_code'.

Open the Clover's Coverage Explorer view. You will find the "Run new report" button there. Choose an HTML report, for instance.

balram maurya July 28, 2013

thanks Marek to give your valuable time..

...


got it... now i have select Custom value radio buttion ...and given the path as above selected directory..

now how i know it is generating new code coverage report,

and how to open Clover's Coverage Explorer view ..??

is you talking about eclipse ide 's Clover's Coverage Explorer view.


thanks for reply and showing intrest.....Marek.
may be the questions which i am asking can be stupid ...but
reply me Marek and let me confirm one thing that this cofiguration will generate
report dynamically when i click on any link after depolying war file...?


Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 28, 2013

No, it will not generate report dynamically. You have to explicitly click "Run new report" every time you want to have an update. Feel free to use <clover-html-report> Ant task + cron job to automate this.

balram maurya July 30, 2013

Hi Marek,

i want to confirm one thing that is.

i add clover in a sample project,have class LoginAction and then i add another class LoginActionTest and i have written the test cases.... if i Run With Clover as
junit Test then it generated the the report and aslo if i upload the war file on server i can see report through run new report.


but now i have my main project which have action,form,utility class and have not any test class.
so how i run this project to generate report using Run with Clover as-> java applet or java application or junit test.

so question is that is it necessary that i write test cases for class or

is it possible without them to generate code coverage report ?? means if i click on gui link then it should tell how much code executed which it tells with test cases.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 30, 2013

Hi Balram,

1) Do you want to have just global, aggregated coverage from both JUnit runs and manual tests?

or

2) Do you want to have per-test coverage from manual test, in which clicking on a single GUI link is treated as a new test?

ad 1) In this case, it should already work for you. In other words, you can run application instrumented by Clover multiple times, no matter whether you're running it via unit tests or via normal application run.

New coverage recording files are being written to a directory where clover.db is located.

So when you generate HTML report after your JUnit + manual test, you shall be able to see code coverage from both (aggregated).

ad 2) In such case this is more tricky, because you have to instruct Clover what is a test case boundary. It could be achieved in two ways:

a) if you have some dedicated class (or classes) which handle URL clicks, then you could use <clover-setup> with <testsources> option to tell Clover what classes/methods are boundaries of your test cases.

For instance, if your application has controller classes named AbcController and each of them has methods named handleRequestXyz, the <clover-setup> would look like:

&lt;clover-setup&gt;
  &lt;testsources dir="..."&gt;
    &lt;testclass name=".*Controller"&gt;
      &lt;testmethod name=".*handleRequest.*"&gt;
    &lt;/testclass&gt;
  &lt;/testsources&gt;
&lt;/clover-setup&gt;

b) if you cannot find such class/method pattern, you could write an artificial JUnit test class with test methods named as your test cases, use a distributed coverage feature and call these test methods on URL clicks.

See https://confluence.atlassian.com/display/CLOVER/Measuring+per-test+coverage+for+manual+tests for more details.

Cheers
Marek

balram maurya July 30, 2013

thanks Marek to give me detail information.

i alredy worked on ad 1) and it was fine ...
but now i want to follow ad 2) -> a). because don't want to use artificial junit test class as in 2 -b)

my apllication is developed in struts 1.3
and i have to invoke contextpath/abc.do

and each class have have execute(.....) function.

i alredy added the clover through eclipse gui.
should i use build.xml ...?if yes should i again configure
clover.jar in build.xml
and also how to use covrage.db and clover setup for class and request method as i told for link like ..localhost://abc/xyz.do

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 30, 2013

Open Project Properties > Clover > Test Classes tab.

Select "Assume all classes matching the following Ant-pattern set are tests ..." toggle.

Enter proper include pattern.

Clover will instrument code in such way that all methods in classes will be marked as test methods (including your 'execute' methods). Having too much actually should not be a big deal.

Alternatively, use Ant and build.xml to fine-tune test pattern with regular expressions for classes and methods.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 30, 2013

I suspect that Clover's coverage recorders were not able to start - either due to missing clover.jar on classpath or due to missing clover.db. Please check server logs (grep -i clover) for any error messages.

balram maurya July 30, 2013

thank you so much Marek to give me your valuable time
your guidence worked for me.

and it started code coverage ...so if i will have
any problem or any queries i will ask.

0 votes
balram maurya July 30, 2013

as you told, i followed your step.

and if i run on server it showing 0 % coverage
even i clicked many links but it was always showing 0%.

am i missing something now ..??

and thanks for giving continous reply..

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events