Maven Tests not Running in sequential Order - maven

I'm using a TestNG framework for my automation project.
While running from command line i'm giving the following command.
mvn clean test -Dtest=Login,OpenImage,Logout
By running the above command it the order of execution was Login->Logout->OpenImage (may be in alphabetical order).
Can anyone help me how to run tests in the given order.
Note: As per my requirement I need to run my tests in the above way it self.
If it was through testNG.xml file then i guess preserve-order will work.
can anyone help me on this.....!!!!!
Thank you in advance..

First why do you need to run tests in a particula order because units should never rely on a particular order. But your question looks like more an integration tests.
If you need to run in order defined dependencies between the tests
#Test
public void serverStartedOk() {}
#Test(dependsOnMethods = { "serverStartedOk" })
public void method1() {}
The above defines the order that serverStartedOk will run before method1..based on the dependsOnMethods...

Related

Gradle how to exclude 1 test file in a multi module project setup?

So we have a multi module project setup, with test all scattered in multiple modules, now we want to execute all of them but exclude 1 test file.
How could we achieve this?
I tried the following:
gradle test -PexcludeTests=*SpecificTests
but the tests get still executed.
for running a singular test I managed to fix it this way:
gradle :multi-module:test --tests '*SpecificTests'
but unfortunately the equivalent for executing all tests but 1 cannot be made with this.
Condition: we need a command we cannot use the testing filter
You can use a project property and define an optional exclude filter, which you can then use from the command line -PexcludeTests='*SpecificTests'.
test {
if (project.hasProperty('excludeTests')) {
exclude(project.property('excludeTests'))
}
}

SpringBoot: how to run tests twice, with two different config files

I am writing a SpringBoot application using a JMS MOM. My application supports two kinds of JMS: EMS and AMQ
My application has many Junit Tests. Of course, whether I use EMS or AMQ the tests are exactly the same and the expected results are also exactly the same. The only difference is the configuration file used.
#RunWith(SpringRunner.class)
#TestPropertySource(locations="classpath:application.yaml")
#ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
public class MyTest {
#SpringBootApplication
#ComponentScan("com.mytest")
static class Application {
}
#Test
public void test() {
...
}
}
What I would like to be able to do is to run my tests twice, one time with an EMS config and one time with and AMQ config: How should I do?
FYI, I am using Maven to build my application. A solution based on a maven trick would be perfectly acceptable for me
Thank you for help
It sounds like a task for a building tool that you using.
For example, for Maven you can write specific test tasks with different active profiles, something like this:
mvn clean test -Dspring.profiles.active=kafka
mvn clean test -Dspring.profiles.active=rabbitmq
mvn clean test -Dspring.profiles.active=activemq
and collect necessary properties in files: application-{profile}.properties
This articles can help you:
how to bind a property file to a current active profile: spring-boot-profile-based-properties
mvn profiles:
introduction-to-profiles
mvn different environments:
building-for-different-environments

Pass in a properties file as a command line argument

I have a test suite (jUnit, Selenium, Cucumber) Maven project.
I need to be able to run the tests from the command line, passing in different properties files as arguments to diversify the test cases. How can I do this?
I currently have a properties reader that has a path to a shared properties folder concatenated with a variable that holds the name of a given properties file. I'm wondering if that can be parameterized for use with a Maven command in the CLI?
I've been researching this for awhile and have found many questions that sound similar to what I'm trying to achieve, but none of the answers have been applicable to my situation/what I'm trying to do. Any advice, ideas, or resources given will be greatly appreciated.
You can simply pass java properties to Maven:
$ mvn clean test -Dmyproperty=some-property-file.properties
Then you can access the property in your test:
#Test
public void test() {
String propertyFile = System.getProperty("myproperty");
assertEquals("some-property-file.properties", propertyFile);
}

I want to run many SOAPUI project xmls using Gradle script, in Linux

I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.
Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,

Why do my Gradle tests run repeatedly?

I have a pretty standard Gradle build that's building a Java project.
When I run it for the first time, it compiles everything and runs the tests. When I run it a second time without changing any files, it runs the tests again.
According to this thread, Gradle is supposed to be lazy by defaut and not bother running tests if nothing has changed. Has the default behaviour here been changed?
EDIT:
If I run gradle test repeatedly, the tests only run the first time and are subsequently skipped. However, if I run gradle build repeatedly, the tests get re-run every time, even though all other tasks are marked as up-to-date.
the gradle uptodate check logs on info level why a task is not considered to be up-to-date. please rerun the "gradle build -i" to run with info logging at check the logging output.
cheers,
René
OK, so I got the answer thanks to Rene prompting me to look at the '-i' output...
I actually have 2 test tasks: the 'test' one from the Java plugin, and my own 'integrationTest' one. I didn't mention this in the question because I didn't think it was relevant.
It turns out that these tasks are writing their output (reports, etc.) to the same directory, so Gradle's task-based input and output tracking was thinking that something had changed, and re-running the tests.
So the next question (which I will ask separately) becomes: how do I cleanly (and with minimal Groovy/Gradle code) completely separate two instances of the test task.
You need to create test tasks in your build.gradle and then call those specific tasks to run a specific set of tests. Here is an example that will filter out classes so that they don't get run twice (such as when running a suite and then re-running its child classes independently):
tasks.withType(Test) {
jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
maxParallelForks = 4 // this runs tests parallel if more than one class
testLogging {
exceptionFormat "full"
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
displayGranularity = 0
}
}
task runAllTests(type: Test) {
include '**/AllTests.class'
testReportDir = file("${reporting.baseDir}/AllTests")
testResultsDir = file("${buildDir}/test-results/AllTests")
}
task runSkipSuite(type: Test) {
include '**/Test*.class'
testReportDir = file("${reporting.baseDir}/Tests")
testResultsDir = file("${buildDir}/test-results/Tests")
}
Also, concerning your build question. The "build" task includes a clean step which is cleaning tests from your build directory. Otherwise the execution thinks the tests have already been ran.

Resources