I'm using cobertura to find out code coverage of my test suite, which tests a java based solution bundled through a jar file, cobertura cmd line reference
I have done the instrumentation part and obtained the instrument class files.
For the second step, I'm not sure whether I need to re-bundle the instrumented class files into a jar file since my test suite uses this jar file or can I simply set my CLASSPATH variable to include the instrumented class file while continue to use original jar file (which contains the uninstrumented class files).
Thanks.
You have to include your instrumented files in the classpath BEFORE any other containers/Folders that may include the same compiled files.
In you case before the jar file with the instrumented files.
You don't need to rebundle.
Another possibility would be to instrument the jar file directly.
Related
My JUnit tests need Java source code files as input. I've created those files under src/test/resources. I read a test resource file from src/test/resources (e.g., src/test/resources/files/SimpleTestClass.java via
final String expectedClass = new String(ClassLoader.getSystemClassLoader()
.getResourceAsStream("files/SimpleTestClass.java")
.readAllBytes());
The behavior that I expect is that the test resource Java files will not be compiled. This is exactly what Gradle does, therefore, running the tests with gradle test works fine.
Unfortunately, running the JUnit tests from within Eclipse results in a compilation of those test resource Java files. The bin folder now includes .class files instead of the .java files.
I could exclude the test resource Java files from the compilation. However, this will also disable Eclipse's Java editor functionalities for those files, e.g., error highlighting or refactoring.
For the test resource Java source code files: How can I keep the Java editor functionalitites in Eclipse, but exclude the compilation of those files so that they still are copied to the bin folder?
When running the test phase my tests fail to the JAI requirement for the code to be run from inside a jar file that contains Specification-Title in the manifest.
Unfortunately mvn test and intellij debug do not build a a jar file (obviously) and so no manifest exists.
Is there an alternative way of setting these values?
I have a .jar file, where I have packaged my maven managed java project which has few Junit test cases as well. Now I want to run test cases from my .jar file. For example, from the source code mvn test will run the test cases, but it is not working for .jar file.
How do I run Junit test cases from my .jar file?
You need to configure the maven-jar-plugin, and include the test classes in the jar
http://maven.apache.org/plugins/maven-jar-plugin/usage.html
have a look also here
http://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html
I am trying to build a Runnable jar file using the Eclipse>Export>Runnable Jar File option.
Things are fine except that it is also exporting my test classes
I am only selecting classes from my src/java folder and not anything from src/test folder
One way out is to add the MANIFEST file later after building as a normal jar. But would like to know if there is a way to prevent tets classes from being exported
In the Java Build Path Source menu add the main and test sources separately. Now in the Deployment Assembly menu remove the test sources.
Is that what you're looking for?
have a look here
I would like to know the difference between extracting and packaging libraries into a jar file from eclipse with the runnable jar file creation.
If my program (runnable jar) uses other classes which require these external libraries(jars), what should I pick?
If you want to put jars into your generated jar file, you can use packaging method.
For example if you are using an Apache library or some other 3rd party jars, you may want to keep these jars preserved in your generated jar. In this case, use packaging.
"Packaging required libraries into a jar file" option puts classes of org.eclipse.jdt.internal.jarinjarloader package into your generated file and this package is just under the root directory of the generated jar file. This option also creates a larger jar file in terms of size due to jar loader classes of Eclipse.
Extracting required libraries will result in putting classes of 3rd party libraries into your jar file by following the package naming convention, e.g. if you open your jar content you can see some classes under org.apache.. packages.
Main class entries are different between the MANIFEST.MF files of these jar files:
Main class entry when you package required libraries:
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Main class entry when you extract required libraries:
Main-Class: YourMainClass
For my use, the principal difference is that packaged JAR files are included intact as a distinct item, hence retaining their copyright information and signature data.
If you choose extract, the class files are pulled out of their original context and stored as if you had originated them, hence possibly violating some licence conditions, although the size of the final JAR will be smaller in this case. Eclipse does warn you about licensing in this case, too.
So, if using third-party JAR libraries, it's professional to always package.
Try it both ways, and open the resulting jar files with a Zip program. Very instructive.
These are mainly two ways to export as a Runnable jar in eclipse.
1). Package required libraries into jar
This will add actual jar files of the libraries into your jar.
This is the cleanest since it separates application class files with
library JARs.
The downside is this makes runnable jar perform very slow.
2). Extract required libraries into generated jar
This way will extract only the actual class files from the libraries
that your application uses and includes in the runnable jar file.
As a result your Jar file will include your application class files
as well as class files of all the libraries used by your application.
This method makes runnable jar perform just like it is run in your
eclipse IDE.