How do I use JMockit with Gradle on the IBM J9 JVM? - junit

I'm using Gradle (Milestone 8a) to run JUnit tests on my project with the IBM J9 JVM, which according to "Running tests with JMockit" requires that I pass the argument -javaagent:jmockit.jar to the JVM. However, JMockit isn't injecting mocked parameters which is causing my tests to fail with "Method (foo) should have no parameters)". The tests run fine in Eclipse on the HotSpot JVM.
I've extended the test task to find the JAR and add the argument to jvmArgs like this:
test {
doFirst {
// Don't do this until the task is actually being executed, because
// as soon as we call testCompile.find the configuration is resolved and
// can't be modified anymore.
jMockit = project.configurations.testCompile.find {
it.name.startsWith("jmockit-")
}
jvmArgs "-javaagent:${jMockit}"
}
}
I've also added JMockit and JUnit to the testCompile configuration, making sure that JMockit is first, and verified this by running gradle dependencies:
dependencies {
testCompile 'com.googlecode.jmockit:jmockit:0.999.13'
testCompile 'junit:junit:4.10'
}
The output of gradle check --debug confirms that the -javaagent parameter is being used:
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] creating process builder for Gradle Worker 1
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] in directory /home/bbobby/webapp
12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#0 = -javaagent:/home/bbobby/.gradle/caches/artifacts-8/filestore/com.googlecode.jmockit/jmockit/0.999.13/jar/a6
ba457e09361f37e386edea176c5ce4fa9ee110/jmockit-0.999.13.jar
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#1 = -ea
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#2 = -cp
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#3 = /home/bbobby/.gradle/caches/1.0-milestone-8a/workerMain/classes
12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#4 = org.gradle.process.internal.launcher.GradleWorkerMain
12:44:14.816 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Started Gradle Worker 1.
I'm pretty sure I've done everything I'm supposed to. Why are my tests failing to run?

This is http://issues.gradle.org/browse/GRADLE-2189, which is already fixed for the upcoming 1.0-rc-1. You can try out the release candidate today.

Related

Junit: Print runtime classpath

I have a diificult ClassDefNotFound problem (see here)
I run my unit tests through maven surefire plugin.
I would like to print out my unit test classpath at runtime. The following code only outputs one entry, namely the surefire jar. (I guess surefire has its own classloader and is using reflection.)
#Test
public void testGetClasspathTest()
{
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
TestSS.getLogger().debug(url.getFile());
}
}
Can someone suggest a way to get the full runtime classpath from within a junit test?
the answer is simple:
mvn -e -X install
This provides full debug output including test runtime classpath

Viewing results of junit test for gradle?

So I currently have the following build.gradle file:
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src/model'
}
}
test {
srcDirs = ["tests/model"]
}
}
dependencies {
compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
that builds successfully when I type "gradle test" into the command line.
However I do the following error when running gradle test:
Creating properties on demand(a.k.a dynamic properties) has been deprecated.
As you can see, my junit tests are all in the folder test/model/ but I was wondering how do I see the results of if my junit tests passed?
You can view my repository here: https://github.com/quinnliu/WalnutiQ
Chingy,
I had to update a couple of things in your build.gradle:
source set for tests
added Maven repository to get JUnit library
apply plugin: 'java'
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDir 'src/model'
}
}
test {
java {
srcDir 'tests/model'
}
}
}
dependencies {
compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Now, the results of $ gradle build:
bender:WalnutiQ demo$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources UP-TO-DATE
:testClasses
:test
model.RetinaTest > test_seeBMPImage FAILED
java.lang.IllegalArgumentException at RetinaTest.java:25
model.MARK_I.SpatialPoolerTest > test_performSpatialPoolingOnRegion FAILED
java.lang.IllegalArgumentException at SpatialPoolerTest.java:60
model.util.JsonFileInputOutputTest > test_saveRegionObject FAILED
java.lang.IllegalArgumentException at JsonFileInputOutputTest.java:69
model.util.SynapsePermanencesViewerTest > test_saveRegionToBeOpenedInSynapsePermanencesViewer FAILED
java.lang.IllegalArgumentException at SynapsePermanencesViewerTest.java:45
49 tests completed, 4 failed
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/demo/development/tmp/WalnutiQ/build/reports/tests/index.html
I think you can take it from here :o)
PS: I would recommend to refactor your project structure to match Maven/Gradle structure, so you don't have to deal with source sets and it will make your build.gradle cleaner.
src/main/java Production Java source
src/main/resources Production resources
src/test/java Test Java source
src/test/resources Test resources
src/sourceSet/java Java source for the given source set
src/sourceSet/resources Resources for the given source set
When you run gradle build or gradle test, there is a build directory that is created.
This directory is where all the build artifacts are placed.
Inside the build directory is a reports directory. This directory is where reports are placed.
For example, pmd reports, junit reports, etc.
The JUnit reports are located in the tests directory. Open up the index.html file in a browser to view the report.
You can specify where the JUnit test results go with the following command within your test block.
test {
reports.junitXml.destination = file('build/test-results/folder')
}

simple gradle build running compass failing

I have a very simple gradle project. I am just trying to run compass. However when I do try to run gradle installCompass the build fails. I included the build script I am using. I only have this script and a single scss file in the project.
build.gradle
apply plugin: 'compass'
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url 'http://dl.bintray.com/robfletcher/gradle-plugins' }
}
dependencies {
classpath 'org.jruby:jruby-complete:1.7.3'
classpath 'org.gradle.plugins:gradle-compass:1.0.7'
}
}
compass {
cssDir = file('public/styles')
sassDir = file('scss')
}
the error I get
A problem occurred configuring root project 'GradleStyleGuide'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find org.jruby:jruby-complete:1.7.3..
Required by:
:GradleStyleGuide:unspecified
this is the result of a dependency check
compass
\--- org.jruby:jruby-complete:1.7.3 FAILED
Here is what happens when I run the build from command line.
Gradle 1.6
------------------------------------------------------------
Gradle build time: Tuesday, May 7, 2013 9:12:14 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0_17 (Oracle Corporation 23.7-b01)
OS: Windows 7 6.1 amd64
C:\Users\me>cd \code\GradleStyleGuide
C:\code\GradleStyleGuide>gradle installCompass
Download http://repo1.maven.org/maven2/org/jruby/jruby-complete/1.7.3/jruby-complete-1.7.3.pom
Download http://repo1.maven.org/maven2/org/jruby/shared/1.7.3/shared-1.7.3.pom
Download http://dl.bintray.com/robfletcher/gradle-plugins/org/gradle/plugins/gradle-compass/1.0.7/gradle-compass-1.0.7.pom
Download http://repo1.maven.org/maven2/org/jruby/jruby-complete/1.7.3/jruby-complete-1.7.3.jar
Download http://dl.bintray.com/robfletcher/gradle-plugins/org/gradle/plugins/gradle-compass/1.0.7/gradle-compass-1.0.7.jar
:installCompass FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':installCompass'.
> Could not resolve all dependencies for configuration ':compass'.
> Could not find org.jruby:jruby-complete:1.7.3.
Required by:
:GradleStyleGuide:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 10.014 secs
I can resolve jruby-complete just fine (using your build script). Chances are that the problem is related to your environment (e.g. no proxy settings configured for Gradle). I recommend to run with --info and check the log output.
After adding a wrapper task and a repository of mavenCentral, outside of buildscript I was able to get this to work.
buildscript {
repositories {
mavenCentral()
maven { url 'http://dl.bintray.com/robfletcher/gradle-plugins' }
}
dependencies {
classpath 'org.gradle.plugins:gradle-compass:1.0.7'
}
}
repositories {
mavenCentral()
}
apply plugin: 'compass'
task wrapper(type: Wrapper) {
gradleVersion = "1.6"
}
compass {
cssDir = file('public/styles')
sassDir = file('sass')
}

addr_out_handler.c(133) No action present. Stop processing addressing

I'm just started to use axis2c (rev 1.5 on linux ) and I rewrite a simple service which is a copy of the add functionality of the math service.
It seems all ok but at the end of the procedure, when the service should send back the result of the sum, it report the error "No action present".
I called my service "ctictrlintf" and inside the ctictrlintf_invoke function I get that node with the 2 parameter to add.
Here the content of the node printed using axiom_node_to_string api.
<ns1:test1 xmlns:ns1="http://ws.apache.org/axis2/services/ctictrlintf">
<param1>40</param1>
<param2>8</param2>
</ns1:test1>
At the end of the function ctictrlintf_invoke is returned a nod ewith result of the addiction.
<ns1:result xmlns:ns1="http://axis2/test/namespace1">48</ns1:result>
What happened after that is reported below.
Somewhere in addr_out_handler.c the program reported the error "No action present" and abort the operation.
[debug] phase.c(210) Invoke the handler AddressingOutHandler within the phase MessageOut
[info] Starting addressing out handler
[debug] addr_out_handler.c(133) No action present. Stop processing addressing
[info] Request served in 0.012 seconds
What mean this error and what action should require the library to complete its work ?
Best reagards, Enzo
Added 18.07.2013 16:56
Inside the config file axis2.xml there is still enable the addressing module
<!-- ================================================= -->
<!-- Global Modules -->
<!-- ================================================= -->
<module ref="addressing"/>
and when the server is started the log report some note about the activation of the addressing
[debug] conf_builder.c(234) No custom dispatching order found. Continue with the default dispatching order
[debug] conf_builder.c(379) Module addressing found in axis2.xml
[debug] class_loader.c(140) /usr/local/axis2c/lib/libaxis2_http_sender.so shared lib loaded successfully
[debug] class_loader.c(140) /usr/local/axis2c/lib/libaxis2_http_receiver.so shared lib loaded successfully
[debug] dep_engine.c(1283) axis2_dep_engine_load_module_dll: DLL path is : /usr/local/axis2c/modules/addressing/libaxis2_mod_addr.so
[debug] class_loader.c(140) /usr/local/axis2c/modules/addressing/libaxis2_mod_addr.so shared lib loaded successfully
[debug] dep_engine.c(1283) axis2_dep_engine_load_module_dll: DLL path is : /usr/local/axis2c/modules/logging/libaxis2_mod_log.so
[debug] class_loader.c(140) /usr/local/axis2c/modules/logging/libaxis2_mod_log.so shared lib loaded successfully
[debug] svc_builder.c(318) DLL path is : /usr/local/axis2c/services/ctictrlintf/libctictrlintf.so
[debug] svc_builder.c(318) DLL path is : /usr/local/axis2c/services/echo/libecho.so
[debug] svc_builder.c(318) DLL path is : /usr/local/axis2c/services/math/libmath.so
[debug] phase_holder.c(139) Add handler AddressingInHandler to phase Transport
and the service code already had the following call
/* Create EPR with given address */
endpoint_ref = axis2_endpoint_ref_create(env, address);
/* Setup options */
options = axis2_options_create(env);
axis2_options_set_to(options, env, endpoint_ref);
axis2_options_set_action(options, env, "http://www.aesys.com/axis2/services/ctictrlintf/test1");
/* Set service client options */
axis2_svc_client_set_options(svc_client, env, options);
/* Engage addressing module */
axis2_svc_client_engage_module(svc_client, env, AXIS2_MODULE_ADDRESSING);
This message is produced by addressing module and this is not a error.
Your service has no addressing support and didn't send or receive any addressing-specific headers.
Information about WS-Addressing support in Axis2/C is here.

Mark Gradle build unstable in Jenkins when JUnit tests fail

I have a Gradle build in Jenkins with various JUnit tests that are executed as part of the build. Now when some of the tests fail the complete build is marked as failed - because Gradle says the build failed.
How can I convince Gradle to succeed the build and then Jenkins to mark the build as unstable? With ant this was no problem at all.
Use the ignoreFailures property in the test task.
apply plugin: 'java'
test {
ignoreFailures = true
}
You can use external properties to solve this problem.
if (!ext.has('ignoreTestFailures')) {
ext.ignoreTestFailures = false
}
test {
ignoreFailures = project.ext.ignoreTestFailures
}
In this setup by default failures will fail the build. But if you call Gradle like so: gradle -PignoreTestFailures=true test then the test failures will not fail the build. So you can configure Jenkins to ignore test failures, but to fail the build when a developer runs the tests manually.
You can include this in your main build.gradle to be applied to all projects and all test tasks.
allprojects{
tasks.withType(Test) {
ignoreFailures=true;
}
}
Since just ignoring the failed test could not be used in my case i found out the following.
If you are using a scripted jenkinsfile. It is possible to wrap your test stage in a try-catch statement.
try {
stage('test') {
sh './gradlew test'
}
} catch (e) {
echo "Test FAILED"
}
This will catch the build exception thrown by gradle but it marks the build as unstable.