JUnit test class execution with command prompt - cmd

How to execute JUnit classes (java not test class) through cmd?
I am working on eclipse for a black-box testing and I have a task to:
Implement a class that is executable from command line

Related

Unable to execute single runner class from gradle command line

I am trying to call specific runner class from command line argument from command line using gradle, however by default all the runner class is getting executed,
gradle test -Dtest=testRunner
however this behaviour is not replicated when executed with maven build tool

Run a single Runner class through gradle command line - karate

I have more than one runner class created in my src/test/java folder. When i run the gradle command by
gradle test -DcatsRunner
it runs all the Runner files inside the folder and not just one. How to run only one Runner file using gradle command line
gradle test -DcatsRunner
You want to run a single test case with gradle.
Running gradle help --task test will give you the following help message:
$ gradle help --task test
Configuration on demand is an incubating feature.
> Task :help
Detailed task information for test
Path
:test
Type
Test (org.gradle.api.tasks.testing.Test)
Options
--debug-jvm Enable debugging for the test process. The process is started suspended and listening on port 5005.
--fail-fast Stops test execution after the first failed test.
--tests Sets test class or method name to be included, '*' is supported.
Description
Runs the unit tests.
Group
verification
The --test parameter is what you are looking for.
In you case:
gradle test --tests catsRunner
If you want to setup a more comprehensive test filtering, please read the test filtering gradle documentation.

Run TestNG.xml through command prompt

I am trying to run testng.xml from command prompt and getting error that main class not found.
How to give reference of org.testng.jar while running testng.xml from command prompt
Have you tried reading documentation?
Assuming that you have TestNG in your class path, the simplest way to invoke TestNG is as follows:
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
If you have your tests and testng.jar in your CLASSPATH the above command should be enough.
Approximate syntax for more complex scenarios:
java -cp "/path/to/test.jar;/path/to/your/tests.jar;/path/to/test/dependencies.jar" org.testng.TestNG testng.xml
where testng.xml is the TestNG config file
More information with examples: Automated test using TestNG chapter

Gradle - Corda flow tests fail when run from the command line

In my project I have a module that contains Corda flow tests written in Kotlin, and using JUnit. Most of the tests pass, except for the flow tests
My assumption is that this is because Corda flow tests require -ea -javaagent:lib/quasar.jar in the command line...
In my gradle.build file I've added
test {
jvmArgs "-ea -javaagent:lib/quasar.jar"
}
And then from the command line I'm running ./gradlew test but I get these errors from the flow tests:
java.lang.IllegalStateException
kotlin.UninitializedPropertyAccessException
Further Investigations
Running ./gradlew test --info suggests that the jvm arguments are being ignored altogether:
com.acme.FlowTests > Issuance flow should be signed by the initiator FAILED
java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM. See https://docs.corda.net/troubleshooting.html - 'Fiber classes not instrumented' for more details.
kotlin.UninitializedPropertyAccessException: lateinit property network has not been initialized
The problem was that I was specifying jvmArgs in the wrong module. Adding the following line to gradle.build of the module that contains the tests fixed the issue:
test.jvmArgs = ["-ea", "-javaagent:../lib/quasar.jar"]

How can I access a test class from Maven's main folder?

I created a Maven project with the standard folder strucure - i.e. src/main/java, src/test/java, etc.
I wrote a class ClassA and a test class TestA.
From the main program of ClassA, I refer to a static member of TestA.
The code compiles, but when I run it, I get: NoClassDefFoundError: TestA.
How can I access TestA from within ClassA?
Instead of solving your issue directly, I would advise to rethink your test design. Maven is perfectly capable of running tests on its own, just enter
mvn test
on the command line. If you want to run a single test class, enter
mvn test -Dtest=MyTest
for a single test method, use
mvn test -Dtest=MyTest#shouldRunPerfectly
It also supports wildcards, so to run some common tests, you could type
mvn test -Dtest=Integration*#shouldBeFaster*.
Most IDEs allow to run tests directly by a shortcut. If I recall correctly, It's Shift+Alt+X then T for Eclipse and Shift+Ctrl+F10 for IntelliJ. IntelliJ also uses the Ctrl+Shift+T shortcut to navigate to the test of the class you are working with.
Maven directory structure emphasizes the separation of the tests from the application and makes it much harder to do what you are planning to.
tl;dr - do it the maven way

Resources