How to ignore Methods during Code Coverage

Hello again. This is a quick tip for you, hope it helps.

Requirements:

  • Programming Language: Java
  • Project Management: Apache Maven
  • Use the artifact “cobertura-maven-plugin” from the “org.codehaus.mojo” group.

Now with the solution:

  1. Create a simple annotation with any name you like.
<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;">&#65279;</span>

public @interface CoverageIgnore() {

}

2. Add the previous annotation to the methods you want to ignore.


@Override
@CoverageIgnore
public User modifyUser(User user) throws DaoException, SecurityException {
  if(user == null) { throw new SecurityException("User null or empty")}

  Userseg userseg;
  List IdProfiles;

  try {
     userseg = userDAO.search(user.getId());
     ...

3. Add the following tags to the plugin in the pom.xml



 org.codehaus.mojo
 cobertura-maven-plugin
 2.6
 
  
   xml
  
  
   true
   [packagename].CovertureIgnore
  
   **/*.class
   **/*Test.class
   **/Test*.class
  
  
 


4. Compile and you should be set. See you at Twitch, guys.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s