Get source code along with report

Hi,

I want to get the instrumented source code before running the tests so that I can see the coverage info for methods/statements by clicking the classes on report. Please let me know how can we do that?

I am building the code, packaging it on one server (build-server) through teamcity. Teamcity creates a checkout directory and then run build.xml. After getting the pkgs I am installing them to different server (test-server) and running tests.

Regards,

Abhinav

1 answer

1 accepted

Accepted Answer
0 votes

You should instrument both application and test code using the <clover-setup> or the <clover-instr> task, next compile these instrumented sources, next package/deploy them to your test machine (you may need to copy clover.jar and clover.db as well), run tests and finally generate a report using the <clover-report> task.

If you're looking for a basic introduction, please have look at:

If you want to learn how to manage Clover in a distributed environment (when build and test servers are separated or when application and tests are running in separate JVMs), please have a look at:

Hi Marek,

Is it mandatory to instrument test code to see coverage info for source code? My tests are integration tests. I am copying clover.jar and coverage.db through teamcity artifacts, should I have to do the same way to source code? Can I zip it then put into artifacts actually the source code is very big?

Thanks again.

Also the build path will be like: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/47becb009e2f5761

So I am not sure how to copy source code to test machine.

Regards.

Is it mandatory to instrument test code to see coverage info for source code?

Yes, it's mandatory to instrument code. This is how Clover works.

You can instrument only application code (and not a test code) if you wish, but in such case you will neither see per-test coverage nor test results in an HTML report. So I recommend to instrument all sources.

My tests are integration tests.

This is fine. But which test framework do you use? Clover recognizes JUnit, TestNG and Spock. In case you use a different framework, you'll have to configure a proper pattern for it in <clover-setup>.

I am copying clover.jar and coverage.db through teamcity artifacts, should I have to do the same way to source code?

I think there is no need to copy sources to your test machine, unless you generate Clover's HTML report on it. What you have to do is to deploy an instrumented version of your classes for testing.

An access to original sources is necessary for:

  • code instrumentation (<clover-setup>) - on your build machine
  • report generation (<clover-report>) - usualy also on a build machine, it depnds on your environment setup

Hi,

I am generating clover report in HTML format and we want to see methods which are not touched or not been covered when the whole tests execution ends. We don't want per test coverage so I think we don't need to instrument tests.

Please suggest.

Regards.

We don't want per test coverage so I think we don't need to instrument tests.

You're correct. In such case you don't have to instrument tests.

Okay. Please let me know how can I get the instrumented source-code means what clover related ant task I can use? My checkout directory on Teamcity is something like: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/47becb009e2f5761

After "47becb009e2f5761" I have project specific dir/sub-dir structure which I want to copy as it is completely on test-server.

Do I have to maintain same directory structure on test server too or I can give anyother location?

Thanks again.

Regards.

You have to use the <clover-setup>. Please have a look at my first answer - you'll find links with code samples there.

Hi Marek, thanks for your response.

Do I need copy src files which are purily .java files or class files (kept in "build" dir) or both to the test server? Means what are accessed when clicking on classes, methods in report??

Please suggest.

Thanks.

You have to copy source files (*.java, *.groovy - if any).

Hi Marek,

Clover-report is not picking my source-code location, my ant task:

<clover-report initString="/home/ta230208/coverage.db">

<current outfile="/home/as185127/results" summary="true">

<format type="html" showEmpty="true"/>

<sourcepath>

<pathelement path="/home/as185127/source_code"/>

</sourcepath>

</current>

</clover-report>

It shows error as:
[clover-report] Failed to render syntax highlights for /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java
[clover-report] java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java (No such file or directory)java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java (No such file or directory)
[clover-report] at java.io.FileInputStream.open(Native Method)
[clover-report] at java.io.FileInputStream.<init>(FileInputStream.java:146)
[clover-report] at java.io.FileReader.<init>(FileReader.java:72)
[clover-report] at com.cenqua.clover.registry.FileInfo.getSourceReader(FileInfo.java:442)
My objective is to replace /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/ to /home/as185127/source_code and after that dir structure is common.
Please suggest.
Thanks.

Hi Abhinav,

I don't know exact layout of your source code directories, but it looks that you don't have Java sources directly under the /home/as185127/source_code.

According to a log, the original location is:

/home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java

so after a build workspace root ('.../work/c504f77d6e43a7da') you have a module name ('Commons') and the 'src/java' source folder.

The <clover-report>/<sourcepath> element requires a list of all source roots and not just the one workspace root. So it should look like this:

&lt;clover-report initString="/home/ta230208/coverage.db"&gt;
  &lt;current outfile="/home/as185127/results" summary="true"&gt;
    &lt;format type="html" showEmpty="true"/&gt;
    &lt;sourcepath&gt;
      &lt;pathelement path="/home/as185127/source_code/Commons/src/java"/&gt;
      &lt;pathelement path="/home/as185127/source_code/OtherModule/src/java"/&gt;
      ...
    &lt;/sourcepath&gt;
  &lt;/current&gt;
&lt;/clover-report&gt;

Cheers
Marek


Hi Marek,

Thanks, yes it works now but I am getting messages for only few files like :

[07:10:12][clover-report] Source file /home/as185127/source_code/Commons/com/teradata/datamovement/commons/schemas/AsterOptionType.java has changed since coverage information was generated[07:10:12][clover-report] Source file /home/as185127/source_code/Commons/com/teradata/datamovement/commons/schemas/DmDaemonTime.java has changed since coverage information was generated[07:10:12][clover-report] Source file /home/as185127/source_code/Commons/com/teradata/datamovement/commons/schemas/KeyColumns.java has changed since coverage information was generated[07:10:12][clover-report] Source file

Is it expected?

And how can I hide error/warnings shown as:

[clover-report] /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/test/java/com/teradata/datamovement/commons/clientservice/DaemonCommandHandlerTest.java (No such file or directory)

java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/test/java/com/teradata/datamovement/commons/clientservice/DaemonCommandHandlerTest.java (No such file or directory)java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/test/java/com/teradata/datamovement/commons/clientservice/DaemonCommandHandlerTest.java (No such file or directory)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(FileInputStream.java:138)

at java.io.FileReader.<init>(FileReader.java:72)

If I put srclevel as false then no source code is shown. It is looking for test dir but I can't remove those from not being compiled as those are in BuildConfig which I can't touch.

Thanks again.

/home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/test/java/com/teradata/datamovement/commons/clientservice/DaemonCommandHandlerTest.java

Did you add the <pathelement path="/home/as185127/source_code/Commons/test/java"> in your <clover-report> task?

Hi Marek,

I don't want unit tests to be in clover report. I can bring the source code for "test" dir too but thinking it is of no use. Can I place empty dir structure? like "/home/as185127/source_code/Commons/test/java" but do not put any java files. Will clover-report ignore and doesn't show warnings?

But I think this will not help, please suggest.

Thanks.

Source file /home/as185127/source_code/Commons/com/teradata/datamovement/commons/schemas/AsterOptionType.java has changed since coverage information was generated

It means that some of your sources in /home/as185127/source_code have a file modification time stamp newer than the time stamp during instrumentation by <clover-setup>.

The most probably you either:

  • updated files modification time stamps when you've copied files from /home/ta230208/TeamCity_Agent_Space/... to /home/as185127/source_code - please check what options of copy command do you use,
  • or another build was running in the meantime which updated these files (for instance, new sources were checked out from a repository).

Use <testsources> with excludes="**/*" to exclude tests from a report. Example:

&lt;clover-report ...&gt;
   &lt;current ...&gt;
      &lt;format type="html"/&gt;
      &lt;testsources dir="test/java" excludes="**/*"/&gt;
      ...
   &lt;/current&gt;
&lt;/clover-report&gt;

Hi Marek,

I tried above but now src/java also getting ignored and ends with:

/home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java

[clover-report] java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java (No such file or directory)java.io.FileNotFoundException: /home/ta230208/TeamCity_Agent_Space/sdvsue800/TeamCity-Agents/ta230208/work/c504f77d6e43a7da/Commons/src/java/com/teradata/datamovement/model/NewJobExecutionInfo.java (No such file or directory)

[clover-report] at java.io.FileInputStream.open(Native Method)

[clover-report] at java.io.FileInputStream.<init>(FileInputStream.java:146)

[clover-report] at java.io.FileReader.<init>(FileReader.java:72)

[clover-report] at com.cenqua.clover.registry.FileInfo.getSourceReader(FileInfo.java:442)

My ant task:

<clover-report initString="/home/ta230208/coverage.db">

<current outfile="/home/ta230208/results" summary="true">

<format type="html" srcLevel="true" showEmpty="true"/>

<sourcepath>

<pathelement path="/home/as185127/source_code/Agent"/>

<pathelement path="/home/as185127/source_code/CommandLine"/>

<pathelement path="/home/as185127/source_code/Commons"/>

<pathelement path="/home/as185127/source_code/Daemon"/>

</sourcepath>

<testsources dir="test/java" excludes="**/*"/>

</current>

</clover-report>

Thanks.

Hi Marek,

Its working fine now.

Thanks a lot. :)

Hi Marek,

One quick query, what are clover_fs_rez files. I find them in my /tmp dir.

Can I remove them anytime means as soon as they are created? Can I enable any option so that those could not be created?

Thanks again,

Regards.

clover_fs_rez files are temporary files created by Clover in order to test file system's time resolution.

For instance, the NTFS has a 2-second resolution of write time. See

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290.aspx

You can freely delete them.

There's no option to not create these files.

Link is broken

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

128 views 6 8
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you