Ignore uncovered line with SonarQube and Cobertura - junit

I am using sonar with Cobertura and a have some classes like this:
How can I make SonarQube/Cobertura to ignore this annotation? I am testing the class, but not in the server context.
I tried the // NOSONAR but it did not work.

This is not possible to tell SonarQube to ignore this annotation. You might wanna try with JaCoCo coverage engine, maybe it will give better results (?).

Related

Conditional skipping of unit tests

I'm currently working on a class, dealing with network issues. Using JUnit 3.8.1 and having a hardware device, that's not always around to test against, I'd like to conditionally suppress individual tests. Is there a way to achive this with a simple annotation like #if(!gatewayAvailable) -> test's suppressed?
Thanx for any pointers, marcus
There is no such feature in JUnit 3.8.1. You have to use JUnit4 and its Assume class.

Gradle: configuration injection vs inheritance

The Gradle docs state (49.9):
Properties and methods declared in a project are inherited to all its
subprojects. This is an alternative to configuration injection. But we
think that the model of inheritance does not reflect the problem space
of multi-project builds very well. In a future edition of this user
guide we might write more about this.
I understand what configuration injection is doing in principle, but I'd like to understand more about the distinctions from inheritance, and why it's a better fit for multi-project builds.
Can anyone give me a few bullets on this?
Got the answer on the Gradle forums.
Essentially, configuration injection allows you to selectively apply properties to subprojects.

junit on checkstyle extensions

I would like to write a junit test for my Checkstyle extension. Can someone show me how to do it? I know there is a project in github called JUnit-Checkstyle-Test-Wrapper. However, I don't see how using this tool would help me get to my extension and verify its values.
thanks.
Probably the best reference for how to test your checkstyle extension (I assume you've added a checker) is to look at the checkstyle source code, and just copy & change one of the existing tests. For example, here is the test for HeaderCheck. This is probably the best way to start. Remember you can actually extend the Checkstyle test classes.
take a look at a lot of examples for custom Checkstyle checks and UTs for them https://github.com/sevntu-checkstyle/sevntu.checkstyle/tree/master/sevntu-checks

Which PMD rules to activate for JUnit tests?

I'm in the middle of setting up PMD as a tool in our team to support us writing better code. Basically I'm building Ant scripts and try to set up some rules for everyone to use.
But right now I hit this problem:
When I write JUnit tests I don't want to use the same rules I apply on our main source code. I don't care that much about String rules (like string dupliates or weird instantiations) in the junit tests.
My questions is:
Is that a fault on my side and should I start writing better JUnit tests?
Should I provide a 2nd set of rules that disables some of the string/design/finalizers rules?
The second option - I don't run PMD against my tests at all. I could and PMD provides some JUnit specific rules. I would definitely use a separate ruleset against the test code though. I expect more String literals and some thing specified instead of using conditionals/loops. After all, I don't want to duplicate the code I am trying to test.
Two things. Why are you trying to set up rules why not using the existing rules? (Special requirements?). And second yes of course Unit tests should have a good quality as well. Your Unit test test you production code so shouldn't they have at least the same quality as your production code?

Ant replace in maven2?

I'm looking for some way to replace patterns in files with values, during build time.
E.g. a configuration file may look the same except that different machines requires different hostnames in some setting. In that case i want to have a template file, where hostname is replaced with ##hostname##
Then when building, I want to create separate versions of the file with the patter replaced with the correct value for each environment.
In ant you could use "replace", is there something similar in maven2? I know that I can run ant form maven, but if theres a maven plugin doing it, I'd prefer that one.
I found http://code.google.com/p/maven-replacer-plugin/
but it's very new...
Suggestions?
Thanks!
The resource plugin is what does filtering in Maven. IIRC it supports the ant syntax as well as the ${foo} maven syntax.
keep up with the maven-replacer-plugin, the project is still alive and well
Maven's resource filtering might help you out.
Why don't you use the Maven-ant plug-in?