Maven Test with Evosuite-generated Test Cases - maven

I am using Evosuite to generate test cases for my app via Maven and I've followed all of the steps that are outlined in the Evosuite documentation.
I see that all of the test classes have been generated and the export copy the classes to the test folder of my project, so I should be able to run mvn test to run the tests, but when I do, I get a series of errors that it cannot find a bunch of classes (it looks like it can't find any of the Evosuite classes from the runtime even though I have the evosuite runtime defined as a dependency in my POM.)
I would love to use Evosuite for all of our apps but if I cannot get the mvn test to run without errors then the product is useless. Can anybody help with this? I have gone over the documentation several times and checked everything and it all appears to be configured correctly. Thank you.

If you have already run mvn evosuite:export to move them to the ./src/test folder then you may need to compile them using javac so they can be executed by maven. Try using this article to compile them all within one command: How to compile multiple Java files when there are Java files in other packages?

Related

How to run tests in a folder in maven

I am using spring-boot. I have my tests segregated in the following manner
tests
|java
|endtoend
|org.mycompany.tests
|integration
|org.mycompany.tests
|unit
|org.mycompany.tests
When I run a mvn test or package everything inside tests folder are running. I want to run the test within individual folders. Intellij is able to run unit, integaration and endtoend separately.
I saw posts for running tests within a package. All my different test folders have the same package structure. So filtering by test packages will not help me.
If intellij is able to run the folders individually, I think I am just missing the command to run it from the cmd line. Please advise.

Error: Could not find or load main class com.networknt.server.Server error

I have a quick question. Do you have a light-4j framework docker image hosted somewhere in which I can just add my API jar and run docker? I am getting a hard time running my APIs generated using codegen CLI in docker. It consistently gives me Error: Could not find or load main class com.networknt.server.Server error
Have you tried mvn clean install exec:exec? If you want to run with the jar file, you need to build with mvn clean install -Prelease to generate the final fat jar.
This is one of the features contributed by one of the members to speed up the testing cycle to avoid building all extra artifacts for each cycle. It might confuse new developers, though. The generated README.md has some information on how to build and start. Let me know it is not clear, and I will add extra info. When you run the build.sh to generate a docker image, it will be built with -Prelease in the script.

problems running state machine examples

Congratulations on the spring state machine, I found it yesterday and have been trying it out, specifically the turnstile example running in STS. I found it very easy and intuitive to build a FSM.
Because spring shell doesn't work well in STS I tracked down the instructions to run the examples from the command line in the reference doc,
"java -jar
spring-statemachine-samples-turnstile-1.0.0.BUILD-SNAPSHOT.jar"
,
but running it got an error
"no main manifest attribute, in spring-statemachine-samples-turnstile-1.0.0.BUILD-SNAPSHOT.jar".
Although not even a novice in using gradle, I tried fixing this by adding this line to build.gradle in the jar section
"manifest.attributes['Main-Class'] = 'demo.turnstile.Application'"
(which doesn't handle the various sub-projects I know) but got this error
"NoClassDefFoundError: org/springframework/shell/Bootstrap".
If it is possible to run the samples from gradle, could you include them in the reference document? I tried running the samples using
gradle run
but it there was no interaction with the shell scripts.
Samples are designed to be run as executable jar and with shell so that you can interact without a need to recompile with every change. Your error indicates that you didn't build that sample jar as mentioned in docs.
./gradlew clean build -x test
This will automatically use spring boot plugin which will add the necessary jar manifest headers to jar meta info to make it a true executable jar. Essentially every every sample is a spring boot app.
Building SM sample projects in Windows Environment:
Open Command prompt (windows key + r -->cmd-->Enter), Change directory to project root folder spring-statemachine-master (Inside the Extracted folder).
Run gradlew install to get all spring dependencies copied to local machine.
Run gradlew clean build -x test to get the spring shell jars built. Courtesy Janne
These steps should ideally get all .jar built, look into \build\libs folder of respective sample project for jar files.
Run the like any other java jar file java -jar [jar-file-name.jar] (make sure to be change directory to jar file directory location).
One more thing where I was stuck was, How to give events to SM:
It's like this sm event EVENT_NAME_AS_DEFINED_IN_CLASS. Ref
E.g.: sm event RINSE --> to washer project

Share Maven run configurations with other developers using Intellij IDEA

We have the following project setup: Maven, Eclipse, Subversion. Eclipse Launch configurations are in a separate docs folder next to the pom.xml. The launch configurations run something like mvn clean install -Pdev or mvn tomee:run -pl something-ear
The good thing is that a shared run configuration is picked up by the IDE and shown in the External Tools run commands. This way, every developer that checks out this project immediately has access to run the build.
We would like to have something similar using IntelliJ IDEA, but I haven't found a good equivalent. What I have considered so far:
Share run scripts
My first idea was to replace the launch configurations with run scripts. I just could not figure out how to have those run scripts run inside IntelliJ IDEA just the way a Maven goal would be executed.
Share IDEA project configuration
The IDEA project configuration (specifically .idea/runConfigurations) inside the checked out directory is not a good solution. We have (speaking one IDEA project with different IDEA modules depending on the task at hand: as a developer you might need multiple IDEA modules (and sub-modules) in the same IDEA project
An IDEA project consisting of the following modules is not something unusal
projectA/trunk
projectB/tags/1.2
projectC/branches/some-change
My preferred solution would remove all IDE-specific configuration from the repository and have some kind of run definitions either in the project folder or a folder next to the pom.xml that a developer can run from the command line or from her IDE of choice.
The optimal solution would let me define something like this in the pom:
<runConfigs>
<default>clean install</default>
<container>tomee:run -pl something-ear</container>
</runConfigs>
This configuration would then be picked up by the IDE and provided as a run or launch configuration to the developer.
Any ideas or suggestions?
Thank you very much!
My current approach is a hybrid solution:
No configuration in the separate modules
One IDEA project configuration with run configurations managed in VCS
The .idea/runConfigurations directory is versioned separately from the project sources. It contains commands with a working directory set relative to the PROJECT_DIR:
<MavenRunnerParameters>
…
<option name="workingDirPath" value="$PROJECT_DIR$/path/to/submodule" />
</MavenRunnerParameters>
When setting up a new project, the developer also checks out this folder and has a set of pre-configured launch configurations for all projects. The downsides are
All launch configurations are managed centrally instead of with the module
The IDEA project directory has a fixed location relative to the modules. If you set up another project, you will have to change the run configurations
The setup does not clearly state how changes to the launch configurations are shared with other developers

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