Sonar jacoco coverage without running junit - junit

I've following setup in my build.xml for running jacoco:
<formatter type="xml" />
<batchtest todir="${reports.junit.xml.dir}">
<fileset dir="${test.dir}">
<include name="**/*.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
But when I run this it's giving me :
[junit] Test FAILED
Now developers are working on fixing the junits, but I need to know if "without" running junits can I still show how much is the unit test coverage in sonar ?

To answer your question, no you can't get coverage data without running the unit tests. However, you can get coverage data even if the unit tests fail. You just need to keep unit test failure from failing the build & thereby preempting the output of the coverage report.
It looks like the default value of the <junit> tag attribute haltonfailure is off. So either remove your on or turn it off explicitly.

Related

ant task to run JUnit tests from a jar (but only files that have tests!)

We're using JUnit inside a custom framework to test an applications behaviour. We're not actually doing unit testing, just leveraging JUnit.
I've created an ant task to run all the tests in the jar file, but unfortunately it's trying to run everything as a JUnit test. Since the jar file contains things besides just the tests (it contains the supporting framework) this is a problem.
Is there a way to make the junit task only run things marked as tests (we use #Test)?
Currently my ant task looks like this:
<target name="test">
<junit printsummary="yes" haltonfailure="no">
<classpath refid="library.third-party.classpath" />
<classpath>
<pathelement location="${basedir}/build/jar/fidTester.jar" />
</classpath>
<formatter type="plain" />
<formatter type="xml" />
<batchtest fork="no" todir="${basedir}/reports">
<zipfileset src="${basedir}/build/jar/fidTester.jar" includes="**/tests/**/*.class" />
</batchtest>
</junit>
</target>
From the Ant JUnit Task documentation:
skipNonTests
Do not pass any classes that do not contain JUnit tests to the test
runner. This prevents non tests from appearing as test errors in test
results. Tests are identified by looking for the #Test annotation on
any methods in concrete classes that don't extend
junit.framework.TestCase, or for public/protected methods with names
starting with test in concrete classes that extend
junit.framework.TestCase. Classes marked with the JUnit 4
org.junit.runner.RunWith or org.junit.runner.Suite.SuiteClasses
annotations are also passed to JUnit for execution, as is any class
with a public/protected no-argument suite() method.

Jacoco: Aggregating branch coverage report of multiple test case method

I am using Ant JUnit.
<for list="${test.classes.list}" param="class" delimiter=",">
<sequential>
<for list="${#{class}}" param="method" delimiter=",">
<sequential>
<jacoco:coverage destfile="${basedir}/jacoco.exec">
<junit fork="true">
......
<test name="#{class}" methods="#{method}"/>
</junit>
</jacoco:coverage>
<jacoco:report>
......
<csv destfile="coverage/#{class}.#{method}/report.csv"/>
</jacoco:report>
</sequential>
</for>
</sequential>
In the property file, I have:
test.classes.list=a.b.C,d.e.F
a.b.C=test1,test2
d.e.F=test1,test2,test3
Jacoco will produce a report for each test case method.
The problem is branch coverage for each class is not accurate as covered branches may be overlapped.
How do I aggregate the reports to get a correct branch coverage for whole project?
JaCoCo comes with Ant tasks to launch Java programs with execution recording and for creating coverage reports from the recorded data. Execution data can be collected and managed with the tasks coverage, agent, dump and merge.
This is an example from their Web page of how to merge a set of *.exec files:
<jacoco:merge destfile="merged.exec">
<fileset dir="executionData" includes="*.exec"/>
</jacoco:merge>

SQL traces not shown in junit

I am working on an application using EJB and OpenJPA. FOr unit testing I use junit.I am running junits using Websphere's embedded container.
EJBContainer.createEJBContainer(map containing db properties);
In persistence.xml I have set :
<property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
I expect SQL traces in console, but no traces are shown.
What else do I need to do for SQL traces?
I'd start by reading the knowledge center documentation. From what I recall, you need to use WAS logging rather than OpenJPA p.xml configuration.

How can I add Snapshot and test variations to my ivy.xml

I'm using ant+ivy+nexus to build and publish my java OSGi projects (just good old jars if you're unfamiliar with OSGi). After the usual mind-melting period one has when engaging with new tech I've got a mostly functional system. But, I now have two dimensions of artifact variation: snapshot/release and main/test.
The main/test dimension speaks for itself really. The snapshot/release is essential for publishing into nexus in a maven-friendly way. (Extremely useful for integration with open-source OSGi runtimes). So, I have the following artifacts on a per-project basis, and I have many many projects:
project-revision.xml (bp)
project-test-revision.xml (b)
project-revision-SNAPSHOT.xml (bp)
project-test-revision-SNAPSHOT.xml (b)
b = successfully building
p = successfully publishing
(I haven't yet got the test stuff publishing correctly)
It's taken me a while to get that far without duplicating code everywhere in my build scripts, but I've managed it... with one big caveat. For the SNAPSHOT branch I append "-SNAPSHOT" to all revisions. In ant I manage to achieve this programatically, but for ivy I'm using a duplicated ivy.xml; ivy-SNAPSHOT.xml. This has
<info ... revision="x.x-SNAPSHOT">
Notice the -SNAPSHOT. Without this I could never get my
<ivy:deliver>
<ivy:resolve>
<ivy:publish>
chain of commands to correctly publish artifact and maven pom. (Remember I have a requirement to make this maven friendly... I'll be damned if I actually end up using maven to build it mind!)
Now I'm stuck introducing the test/main dimension. I'm ideally looking to publish
project-test-revision(-SNAPSHOT).jar
(Note the optional snapshot). I really don't want to do this by specifying
<info ... module="project-test" ... >
as opposed to <info ... module="project" ... > in yet another ivy file. If I went this route (like I've already started) then I simply end up with loads of ivy-Option1-Option2...-OptionN.xml files. With each new two-value variation doubling the number of build and ivy files. That's crap. There's got to be a better way. I just can't find it.
If you have managed to successfully get ivy publishing artifacts with embellished names from one ivy file, would you mind posting the configuration snippets that achieve this? Would be extremely useful. (Don't forget maven won't know about configurations so I need to get the variations into the filename and pom).
Many thanks
Alastair
Ok, update: I've now got the artifact publishing. I struggled a little while I had the test conf extending the default conf. I'd get a complaint during publishing that the default configuration artifacts weren't present... something I don't care about while only publishing the test case. By making them independent but overlapping I get back fine-grain control of what to publish.
BUT!!!!! There's no viable test pom - that's NOT publishing yet. Well, actually it does publish, but it contains data for the non-test case. So this is still not maven friendly. If anyone has suggestions on this that'd be great.
either way, the code I'm now using, in case it helps you too:
ivy.xml:
<info
organisation="MY_ORGANISATION"
module="MY_PROJECT"
status="integration"
revision="1.0-SNAPSHOT">
</info>
<configurations>
<conf name="default" description="Default compilation configuration; main classes only" visibility="public"/>
<conf name="test" description="Test-inclusive compilation configuration. Don't forget to also add Default compilation configuration where needed. This does not extend default conf" visibility="public"/>
</configurations>
<publications>
<artifact name="MY_PROJECT type="jar" ext="jar" conf="default"/>
<artifact name="MY_PROJECT type="pom" ext="pom" conf="default"/>
<artifact name="MY_PROJECT-test" type="jar" ext="jar" conf="test"/>
<artifact name="MY_PROJECT-test" type="pom" ext="pom" conf="test"/>
</publications>
<dependencies>
<dependency org="MY_ORGANISATION" name="ANOTHER_PROJECT" rev="1.0-SNAPSHOT" transitive="true" conf="*"/>
<dependency org="junit" name="junit" rev="[4,)" transitive="true" conf="test->*"/>
</dependencies>
build.xml:
<property name="project.generated.ivy.file" value="SNAPSHOT_OR_RELEASE_IVY_XML_FILE" />
<property name="ivy.publish.status" value="RELEASE_OR_INTEGRATION" />
<property name="project.qualifier" value="-SNAPSHOT_OR_EMPTY" />
<property name="ivy.configuration" value="DEFAULT_OR_TEST" />
<target name="publish" depends="init-publish">
<ivy:deliver
deliverpattern="${project.generated.ivy.file}"
organisation="${project.organisation}"
module="${project.artifact}"
status="${ivy.publish.status}"
revision="${project.revision}${project.qualifier}"
pubrevision="${project.revision}${project.qualifier}"
conf="${ivy.configuration}"
/>
<ivy:resolve conf="${ivy.configuration}" />
<ivy:makepom
ivyfile="${project.generated.ivy.file}"
pomfile="${project.pom.file}"
/>
<ivy:publish
resolver="${ivy.omnicache.publisher}"
module="${project.artifact}"
organisation="${project.organisation}"
revision="${project.revision}${project.qualifier}"
pubrevision="${project.revision}${project.qualifier}"
pubdate="now"
overwrite="true"
publishivy="true"
status="${ivy.publish.status}"
artifactspattern="${project.artifact.dir}/[artifact]-[revision](-[classifier]).[ext]"
conf="${ivy.configuration}"
/>
</target>

Spring integration delayer element

I'm trying to configure my spring integration and want to use the element, which basically sits between a retryFilter and a queue.
All works fine if I go straight from the retryFilter to the queue, however, as soon as I put the delayer element in between them, the config file fails to be loaded (as happens when there is an error in it).
Config for this section is as follows:
<!-- Retry filter -->
<filter
input-channel="retryChannel"
ref="retryFilter"
method="doRetry"
output-channel="queueChannel" />
<channel id="delayChannel" />
<delayer input-channel="delayChannel" default-delay="10000" output-channel="queueChannel"/>
<channel id="queueChannel">
<queue capacity="100" />
</channel>
<poller id="poller" default="true">
<interval-trigger interval="1000"/>
</poller>
Any help greatly appreciated.
Dave
I've tried out your sample and got it working fine on Spring Integration 2.0.0.BUILD-SNAPSHOT. You can see my commit here:
http://github.com/iwein/Spring-Integration-Sandbox/commit/c274a12f057b6750dcf18663486a99970368e68e
There are a couple of things I changed:
channel renames (in, out) instead of
longer names
filter outputs to
delayer input, instead of passing by
the delayer
Are you using an older version of Spring Integration perhaps?
You can check out my little gradle project ( http://github.com/iwein/Spring-Integration-Sandbox/tree/master/quick-samples/router-test/) which could help you experiment. If you still can't get it working it would be good if you shared a stacktrace and the exact version you are using.