Getting "File not found exception" while running citrus tests during project build - citrus-framework

I have a method like this which executes xml files located in a project package
#Test
#CitrusXMlTest(packageScan="com.something.xxxx")
public void citrusTest()
{
}
while running normally using testng it was executing fine but while building with maven during test phase tests are failing because of file not found exception. But while mentioning the path relate windows file system the tests were executing fine like this
#CitrusXMlTest(packageScan="file:D:\\xxx\\xyz")
How to make citrus to execute xml test cases that are in class path. your help is really appreciated.

You have to create the package name mentioned in the package scan under sec/test/resources not in the src/test/java

Related

IntelliJ build wrong JAR: Could not find or load main class

I have a simple example
public class FileSystemReadFile {
public static void main(String[] args) throws IOException {
System.out.println("Reading the file" + args[0]);
}
}
which is created in IntelliJ where I want to build JAR file; So what I did:
Added Artifact with dependencies (presumably I have some);
Ensure that MANIFEST.MF is located in src\main\resources\META-INF\ as it is already mentioned somewhere here on the site.
Run Artifact build which gave me JAR file in out folder and I run that jar file that said me "Could not find or load main class" java <name>.jar
You may see that main class is added into MANIFEST and location of manifest is also fine.
When I open that created JAR file, I see the same MANIFEST content, I see lots of dependency modules, but I don't see my class!
I suspect that is a cause. Any ideas?
If you include any signed JARs in your app and then use IntelliJ to build artifacts, it will extract the JARS and bundle them with your compiled output.
This then causes a JAVA security exception. I've seen this with Eclipse Paho and Bouncy Castle which are signed.
You can check if any of the library JARs you are using are signed using the jarsigner tool.
jarsigner -verify -verbose <path to library JAR>
Change your IntelliJ artifact setup so that these get bundled as libraries instead of being extracted. Extraction invalidates the certificate as you'd expect.
Try creating a dummy project with just Main. Add 1 library JAR (that you are trying to build with) at a time. Build an output JAR each time until Main breaks. That's how I found this.
IntelliJ should warn you.....
Not sure what was with IntellJ, but I rebuilded artifacts again and it was ok.
hadoop jar <Jar-name>
java -jar <Jar-name>
Everything is working fine.

Run a JMH benchmark for gradle project in eclipse

Is there any direct way to run JMH benchmarks in eclipse for a gradle project.
I tried but faced issues like
No benchmarks to run (then copied manually the generated META-INF witch Mircobenchmark file in resources)
Then it gave generated.package_name.testClass class not found exception.Adding this to the build-path->source gives errors as it expects package name as gradle/classes/generated/package_name

how to use JUNIT using makefile?

I am very new to JUNIT. I have Makefile to compile my code and which will generate a jar file and now I want to run my JUNIT test case for that.
I not sure how to find out .class file using JAR. I am using LINUX as I know I need a .class file to execute a JUNIT case.
can some one help me?
from http://c2.com/cgi/wiki?UnitTestCookbooks:
I use JavaUnit for my unit tests. For a class Foo, its source is in
Foo.java. Its unit test lives in a separate class, with the source in
TestFoo.java. A command line invokes the unit test, in either console
mode or with a GUI. I use the console mode tester:
java junit.textui.TestRunner TestFoo
I build an "all-in-one" test suite for a package, which runs all of
the unit tests in the package. It's called TestAll. This is usually
the test I run when working on the package.
I add a rule like this to my makefile:
test: TestAll.class
java junit.textui.TestRunner TestAll
when I run "make test", Test'All.class gets built (through another
rule) and then junit is run with the standard command-line.

Gradle project.sourceSets.main.runtimeClasspath always blank

I'm writing a Gradle plugin to generate Java code from WSDL. Problem is, my task does not find the Java class I'm trying to execute and blows up at runtime with a ClassNotFoundException even though the necessary jar is listed as a compile dependency. I'm using project.sourceSets.main.runtimeClasspath but have tried compileClasspath, adding a build script section to the build file, using configurations.runtime, all to no avail. Note that my project has no Java src code, just Groovy.
Any ideas? The task, a unit test and the build file can be found here:
https://gist.github.com/abhijitsarkar/8432347
c.f.: cross posted on the Gradle forum
It turns out that because my plugin uses project.sourceSets.main.runtimeClasspath, the client needs to declare the dependencies with runtime scope. It is not enough to have the dependencies declared in the plugin project only.

Classpath problems when running JUnit tests from Eclipse with Gradle build

I have a Gradle project that declares a test-only dependency on an XML data file, and then loads the file from the classpath. When I run the tests directly in Gradle from the command line, everything works fine, but when I run "gradlew eclipse", refresh the project in Eclipse, and then try running the test from Eclipse (Debug As -> JUnit Test), the test fails because it's unable to find the XML file and the classpath (as accessed from the Properties context menu item on the process in the Debug view) shows no indication of the XML file being included on the classpath.
The behavior I'm seeing has some commonality with http://gradle.1045684.n5.nabble.com/gradle-junit-tests-resources-and-classpath-td4418753.html#a4420758, but Sean's problem was the reverse: his tests ran properly under Ant (but he never mentioned trying to run directly from the Eclipse JUnit plugin), but not under Gradle.
Here's the relevant part of build.gradle:
dependencies {
testCompile group: 'com.mycompany', name: 'MyConfigFile', version: '0.0.0+dirty', ext: 'xml' }
Because the only resources that URLClasspathLoader can load directly from the file system are JARs, I'm using the following static method to search the classpath for files that match the filename I need to load:
public static String getFullPathForResourceDirectlyOnClasspath(String nameFragment) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
for (URL url: ((URLClassLoader)cl).getURLs()){
String fullPath = url.getFile();
if (fullPath.contains(nameFragment)) {
return fullPath;
}
}
return null;
}
I call that method as follows:
getFullPathForResourceDirectlyOnClasspath("/MyConfigFile-");
When I run that code from Gradle ("gradlew build"), it finds the file and my test succeeds. When I run it from Eclipse (Debug As -> JUnit Test), it fails to find that file on the classpath (because the Eclipse JUnit plugin doesn't put it there) and that call returns null.
I've tried changing the configuation from testCompile to compile to see if that made a difference, but it doesn't change anything (and perhaps tellingly, my .classpath doesn't have any entry for the XML file even when the compile configuration is selected).
Does anyone know of a way to make this work? Am I just missing something that should be obvious?
It seems that you are abusing the class path to pass a single argument (the absolute file path of the XML file) to a test. Instead, you should either put the XML file on the (test) class path in the correct way (it needs to go into a directory or Jar file that's listed on the class path) and load it correctly (e.g. with getClass().getClassLoader().getResource("some/resource.xml")), or pass the file path to the test as a system property. Naturally, the latter will be harder to make work for different environments (say Gradle build and IDEs).