how can I run maven test case - maven

I have create a small web project using maven.so I want to add test classes and directory to that project.I'm using eclipse as IDE my source folder is "src/main/java" I added test source folder "src/test/java" and added one test class with one test selenium casetry to compile and run it using "mvn test" command,But console only shows "run 0 failure 0 error 0 skip 0",Can any one explain me how to run my testcases properly,is there any configurations to do ?
thnxx

mvn test runs unit tests without additional configuration, but for selenium you need to refer to selenium maven plugin.
If your tests are not in the default location src/test/java, you can specify the alternate location as follows:
<testSourceDirectory>${basedir}/my/alternate/location</testSourceDirectory>

Related

What is relation of Cucumber feature files with Test Runner file in Karate?

I have found if I only add karate core dependency and run my tests, they run fine and report is generated.
So what is importance of making a test runner class? I can run my karate tests without it as well. Kindly explain!
With Karate runner class , you can use #KarateOptions to include or exclude feature files that you want to run eg #KarateOptions(features = "classpath:FeatureFiles/test.feature" , tags = "~#Smoke") will run all feature files other than the one having #Smoke tag .
How to pass parameter to run Karate tests from cmd/terminal as maven project
If we want to run only 'Smoke' tests then code can be written as :
Open cmd/terminal
cd 'karate project path'
mvn test -Dkarate.options="--tags #Smoke classpath:FeatureFiles"

Gradle Cucumber test generates build folder on daemon instead of project directory

I have a test automation project where basically I run cucumber test via gradle task. What's weird is that the build folder is generated on .daemon folder instead of the project directory. E.g.
/Users/my_user/.gradle/daemon/5.6
Whereas it should be on:
/Users/my_user/my_project/build
Weirdly enough this seems to only happen on my local. Is there anything I might have missed on setting up the gradle?

Maven Test with Evosuite-generated Test Cases

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?

Running a single test with invoker plugin

Following is the directory structure for my integration tests
/src/it/first-test
-->my-test
-->build.log
-->inoker.properties
-->pom.xml
-->verify.groovy
When I try to run a single integration tests as described https://maven.apache.org/plugins/maven-invoker-plugin/usage.html. It gives a message that ' No projects were selected for execution' Here is the command I used to invoke the project
/src/main> mvn invoker:run -Dinvoker.test=first-test/my-test*
How should I make sure the test is run?
It looks like you misunderstood the docs how to structure your integration tests. The first integration test should be located /src/it/first-test the second integration test should be located /src/it/second-test which means your folder my-test should be removed...Furthermore you should start the integration test from your project root and not by mvn invoker:run you should use mvn verify -Dinvoker.test=first-test instead...
It looks like you are executing it from src/main. Try it again from the root of the project (where the pom.xml is located).

How to Build a maven project using script file?

I have created a maven project in STS.I completed the development and testing code for my project.If now I want to run or build this project, then I have to do the following
Right click on the project-->Run as-->Run on Server (or)
Right click on the project-->Run as-->Maven Build
If I want to run the test code then
Right click on the class file-->Run as-->Run JUnit
But I want to create a text file I mean script file to run all these commands when I run this script file from the cmd prompt. I have found out on a web site that I should create a PowerShell file, So I don't cognize how to compose a script file like this, is there any example file for it ?
Please, anybody can help me
You can just run mvn clean install on your project root folder (i.e. where your pom.xml file is) in cmd prompt. This command will trigger your project default build lifecycle covering a number of build phases including:
validate
compile
test
package
integration-test
integration
verify
install
During these build phases, Maven will validate and compile your project, run tests (if any) against your codes, package the resultant binaries into say, a JAR file, run integration tests (if any) against your JAR, verify it, and then install the verified package to your local .m2 repository.
If you really want a script, then just add mvn clean install to your batch file.

Resources