How to generate test cases for a jar file using Randoop - randoop

I have generated a jar file in intelliJ and wanted to generate test cases for that jarfile. Can anyone help with command to generate the test cases.
I tried using this command
java -Xmx3000m -classpath "../out/artifacts/trans_locator_2_jar:$RANDOOp_JAR" randoop.main.Main gentests --testjar=trans-locator 2.jar

Related

how to run scala .jar with external jar files in terminal

I have my .jar built from scala classes and it has an external dependency with other.jar. Please suggest how should I run my jar files in terminal. The command I tried is
$scala my_scala.jar external.jar
It works same way as running java program. Try this
scala -classpath <your_scala_jar>:<external_jar> <package.MainClass>

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.

Jython can import lib when run in a single myapp-with-dependencies.jar but not when jython is separate

I have an application which consists of some Java classes and some Python scripts; I use Jython from my Java code to invoke the Python scripts.
My application is built using Maven, and produces an ordinary .jar file containing the compiled Java classes, and the Python scripts as resources. I also use maven-assembly-plugin to generate a myapp-with-dependencies.jar that contains the same plus bundles in the contents of the Jython dependencies.
When I run my application using the with-dependencies jar:
java -classpath target/myapp-1.0.0-SNAPSHOT-jar-with-dependencies.jar com.example.myapp.Main
...it works as expected. But when I run it using two separate jars:
java -classpath "target/myapp-1.0.0-SNAPSHOT.jar:/Users/richard/.m2/repository/org/python/jython-standalone/2.5.3/jython-standalone-2.5.3.jar" com.example.myapp.Main
...it fails: when I ask Jython to execute "import mylib" I get an exception:
ImportError: No module named mylib
In both cases, the exact contents of the classpath should be completely identical, the only difference is that in the first case everything is in one jar, but in the second case it is split across two jars.
What could be causing this behaviour?

Run junit4 test from cmd

I tried to run junit4 test case from command line using:
java -cp junit-4.8.1.jar;test\Dijkstra;test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00
but I got the following error:
java.lang.NoClassDefFoundError: graph/shortestgraphpath;
while the test case is working without any problems in eclipse.
Hint: in eclipse, shortestgraphpath was added in Referenced Libraries.
You need to the jar file containing shortestgraphpath to java class path.
java -cp junit-4.8.1.jar;test\Dijkstra; test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00
The class path is the value that you pass to java with -cp so in your question you just supply junitand your compiled classes.
Try updating it with the jar file with the missing class.
java -cp junit-4.8.1.jar;<path to jar file>;test\Dijkstra;test\Dijkstra\bin org.junit.runner.JUnitCore Data0PathTest00
You might have to add additional jar files as well. I recommend that you take a look at some build tool to help you build and run your java applications for example Maven, Gradle, Buildr.

ClassNotFoundException: Running JUnit Tests in Eclipse

I have a project with src, classes & tests. I keep my JUnit tests in the tests folder.
I keep getting a ClassNotFoundException while running them in Eclipse.
I tried running them using from the Command line.
javac -d classes src\brick\*.java test\brick\*.java
The compiler reports 20 errors telling me that the package org.junit does not exist.
Could anybody help me?
Thanks.
What are you using to manage your dependencies (maven, contained in a lib dir)? Are all of the necessary jars in your classpath?
Javac needs to know where your JUnit jar is located in order to compile your classes.
You should try something like:
javac -cp <path to junit jar> -d classes src\brick\*.java test\brick\*.java
When in Eclipse, you need to add the JUnit jar to your project. Normally this is
done automatically if you have a test case...