I would like to pass some parameters to jUnit while testing. I know, for example, that it can be set showoutput to 'yes'.
How to do this from command line or from Eclipse run configuration?
Params can be passed to Java like this:
java com.example.foo.bar -Dparam1=val1 -Dparam2=val2
So, running jUnit and passing params works in the same manner, create a new configuration, and pass the params as VM options.
java -cp .:/usr/share/java/junit.jar org.junit.runner.JUnitCore -Dparam1=val1 [test class]
Related
Is there an equivalent of the -j command-line option when launching JMeter using Java?
I'm running a series of test scripts that each need to have a custom log name - normally I'd just define each log location using -j, but in these cases they need to be launched through Java.
If you have possibility to amend the java code and invoke System.setProperty function :
System.setProperty("jmeter.logfile", "/desired/path/to/jmeter.log)"
If you don't:
either pass the property via -D command line argument like:
java -Djmeter.logfile=/desired/path/to/jmeter.log ....
or add the next line to system.properties file:
jmeter.logfile=/desired/path/to/jmeter.log
More information:
JMeter Properties Reference
Apache JMeter Properties Customization Guide
Overriding Properties Via The Command Line
Is there any way to run JUnit test cases with program arguments, VM arguments and working directory?
I've tried with org.junit.runner.JUnitCore, but I can't find the way to pass these parameters.
You can pass system parameters with the -Dproperty=value
Program arguments are just passed at the end of the java command line. However, they will be passed to Junit's main method. so you cannot use them in your test class. If you want to use some parameter in your test class, set a system parameter and retrieve it with System.getProperty(String) in your code.
So the command line would look like this (you probably need to set other options like classpath):
java -Dfile.encoding=UTF-8 -Dmy.param=foo org.junit.runner.JUnitCore org.package.MyTest
For the working directory I would change to the desired directory with cd before invoking JUnit.
I want to test hbase using its test cases. I downloaded the project from this link and followed the instruction to test the project, which is simply running the command line
mvn test
There is no problem up to here. What I want to do is to run test cases with jvmti agent. The agent works perfectly fine, I tried it on several java files. Normally, I call my agent to test a java file using
java -agentpath:/path/to/agent/agent.so javaProgram
In this case, the project use maven and I am not good at pom files. I tried to use
alias java="java -agentpath:/path/to/agent/agent.so "
However it did not wok. How can I test hbase with my agent?
You can pass JVM arguments to maven by using the MAVEN_OPTS environment variable:
export MAVEN_OPTS=-agentpath:/path/to/agent.so
A more generic solution is to use JAVA_TOOL_OPTIONS environment variable.
On linux: export JAVA_TOOL_OPTIONS=-agentpath:/path/to/agent.so and then run mvn
I am seeing some code are started like
java MainClass run -cp ******
I have two questions here,
why using run
why specify another classpath following run, any reason or benefit?
In your example, "run" is only an argument of the program, not the JVM. It is not a keyword or anything. The program will simply be passed it as a String.
The -cp argument seems to be also an argument to the program.
From the look of the command line, I guess the MainClass program is used to run another class, which is looked for in the classpath defined by the -cp argument. So, neither "run" nor "-cp ..." are actually used by the VM to run MainClass, but by MainClass itself to run another program.
run, -cp, and ****** will be passed as arguments to the main function in the java class MainClass.
Anything on the command-line, after the class name, are arguments to the class, not arguments to the java VM.
So I have two bash scripts. One for calling the bytecode using the "scala" command, the other to call the same code using the "java" command. My problem is the following, when I use scala, I can see that I can get about 80 threads ( which I created, and shows in my "Task Manager" ) while when I use the java command, I only get about 20 threads created. instead of 80. What is the equivalent "define" option under java for actors.corePoolSize and actors.maxPoolSize?
These are my bash scripts.
The first has the following:
JAVA_OPTS="-Xmx1g" scala -cp bin com.mcmc5.Main -Dactors.corePoolSize=60 -Dactors.maxPoolSize=5000
the second has:
java -cp scala-library.jar:bin com.mcmc5.Main -Dactors.corePoolSize=60 -Dactors.maxPoolSize=5000 -Xmx1g
As far as I know, you can set System Properties in your application:
System.setProperty("actors.minPoolSize" , numberOfActors)
System.setProperty("actors.maxPoolSize" , numberOfActors)
System.setProperty("actors.corePoolSize", numberOfActors)
The way you have defined your properties using java looks fine. Have you considered setting the actors.minPoolSize property? This is exactly how I configure my actor-based applications.