mvn compile exec:java -Dexec.mainClass=com.TestMain
Resolution Maven : Fatal error compiling: tools.jar not found:
Maven Error
Notes
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project camel-templates: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre7\..\lib\tools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Resolution
Go to Eclipse windows->Preference and select java
Click on installed JRE and edit-> Add external jar and select tools.jar from JDK lib folder and add it.
How to skip tests in Maven
There are two ways we can skip the tests in maven
1. Using skipTests option pom.xml
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.15</version><configuration><skipTests>true</skipTests></configuration></plugin></plugins></build>
2. Skip tests as argument (During command line maven install)
$ mvn install -Dmaven.test.skip=true
Cobertura Line and Branch coverage Example
1. What is Cobertura ?
Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
2. Cobertura Advantages and Features
- Cobertura is a open source Java tool
- Helps to get the code coverage details
- It shows the percentage of line and branch test cases have been covered
- Cobertura report shows which line of code is lacking of test cases
- It can be executed with Maven, Ant or command line
3. What is Line and Branch Coverage?
Line coverage –> During the test cases run how much percentage of lines have been covered
Branch coverage-> During the test coverage how much percentage of branches have been covered.
4. Cobertura Example
Below example will show how cobertura calculating line and branch coverage.
1. Create a Maven Project and add below plugin/configuration in pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- cobertura -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<instrumentation>
<includes>
<include>com/pretechsol/**/*.class</include>
</includes>
</instrumentation>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
2. Create a Sample Java Program and its Junit Test
public class SimpleValidate {
public String validation(String name, String gender) {
if (name.equals("")) {
System.out.println("name should not be null");
}
if (gender.equals("")) {
System.out.println("gender should not be null");
}
String result = null;
if (name.equals("pretech")) {
if (gender.equals("male")) {
result = "success";
} else {
result = "fail";
}
} else {
result = "try again";
}
return result;
}
}
3. Junit test class
import org.junit.Before;
import com.vinod.SimpleValidate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.Test;
public class SimpleValidateTest {
SimpleValidate simpleValidate = null;
@Before
public void setUp() throws Exception {
simpleValidate = new SimpleValidate();
assertNotNull(simpleValidate);
}
@After
public void tearDown() throws Exception {
simpleValidate = null;
}
@Test
public void testSimpleValidateaValidation() {
String result = simpleValidate.validation("Vinod", "male");
assertEquals("try again", result);
}
@Test
public void testSimpleValidateValidation1() {
String result = simpleValidate.validation("", "male");
assertEquals("try again", result);
}
}
Run it (Use below command)
mvn clean install cobertura:cobertura
http://cobertura.sourceforge.net/
Confusion Matrix + Precision/Recall (Super Simple, With Examples)
Confusion Matrix + Precision/Recall (Super Simple, With Examples) 1) Binary Classification Setup Binary classification means the model p...
Featured Posts
-
In this example we will see how do to the file encryption and decryption using Apache Camel using pgp 1. Generate pgp keys In order to do t...
-
Spring provides a JMS integration framework that simplifies the use of the JMS API, the JmsTemplate class is the core class which is availab...
-
The selective consumer is consumer that applies a filter to incoming messages so that only messages meeting that specific selection criteria...
-
Apache camel API has the inbuilt kafka component and it is very simple to create producer, consumer and process messages. Here is one simple...
-
Apache camel provides intercepting feature while Exchanges are on route. Camel supports three types for interceptors ( See more about Camel ...
-
Maven Error Notes [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on projec...
-
In the previous example ( Mocking Static methods ) we created mock values for Static methods, in this example we will see how to mock new in...
-
🔢 Java Sorting Algorithms — Step-by-Step with Iterations Sorting is a fundamental concept in programming and data structures. Below are t...
-
Itext PDF is an open source API that allows to create and modify pdf documents in java. In this example we will see how to create and and i...
-
Camel Timer component is used to generate or process message exchanges when a time fires. Here is one example to print ‘Hello world ‘ in eac...
