How to separate and run tests

Hi Does anybody have example how to separate and run (for example integration) tests?

I have java project src/ —java —test/ ------intTest.java ------common1Test.java ------common2Test.java

I want to start intTest.java only.

thanks

Hey Maksym, you can seperate tests by creating multiple test tasks and use exclude and include statements to group them. Assuming you’re using the java plugin, you can simply add a 2nd test task to the existing test task:

test{
 include "**/*"
 exclude "**/intTest**"
}
  task integTest(type: Test){
     include "**/intTest**"
}

hope that helps, cheers, René

Hi Rene

Thank you for answer.

I have next gralde.build file

apply plugin: 'java'
  repositories {
    mavenCentral()
}
  test{
    include "**/*"
    exclude "**/testBugs**"
}
task bugTests(type: Test){
     include "**/testBugs**"
}
  dependencies {
    compile 'org.testng:testng:6.0.1'
    compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.25.0'
    compile 'org.seleniumhq.selenium:selenium-java:2.25.0'
    compile 'org.seleniumhq.selenium:selenium-chrome-driver:2.25.0'
}

and result is

D:\Gradle\selenium>gradle bugTest
:compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processResources
:classes
:compileTestJava
Note: D:\Gradle\selenium\src\test\java\com\avid\acs\selenium\AdminPageBugsTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources UP-TO-DATE
:testClasses
:bugTests
  BUILD SUCCESSFUL
  Total time: 9.37 secs

no tests are run

Hi Rene

please, see my comment below.

hey, what tests are executed when executing the task “test”? Seems that there is something wrong with the chosen pattern. is bugTest a package in your tests? try changing your pattern to /bugTests/

cheers, René

all tests are executed. If I use pattern for

test {

include “**/Login*” … }

than “Login…java” tests are executed only on “gradle test”

Do you think problem in pattern for new task?

Is bugTest a package in your tests? try changing your include pattern to

include **/bugTests/**

Hi Rene

What I have. Structure of project is src/ —main/ ------java.com.projectName/ ---------source file of project —test ------java.com.projectName/ ---------LoginTest.java ---------NewBugsTest.java ---------OldMainTest.java —testBugs ------java.com.projectName/ ---------NewBugsTest.java

There is two ways for separating tests 1. create new package - testBugs with NewBugsTest.java 2. filter executed test (I want to run NewBugsTest.java)

For first way I used patterns

include "**/testBugs/**"
include "**/testBugs**"
include "*/testBugs/**"
include "/testBugs/**"
include "testBugs/**"
include "**/testBugs/*"

nothing were executed.

Second way patterns

include "**/**BugsTest**"
include "**/**BugsTest*"
include "**/*BugsTest*"

If I use

test{
    include "**/Login**"
}

than it works fine with command “gradle test”. But if I use it in

task bugTests(type: Test){
     include "**/Login**"
}

than it does not work with command “gradle bugTests”

Whole pattern of gradle.build is

apply plugin: 'java'
  repositories {
    mavenCentral()
}
  test {
    useTestNG()
    include "**/**"
}
task bugTests(type: Test){
     include "**/testBugs/**" // <<<< here I used patterns from above
}
  dependencies {
    compile 'org.testng:testng:6.0.1'
    compile 'org.seleniumhq.selenium:selenium-firefox-driver:2.25.0'
    compile 'org.seleniumhq.selenium:selenium-java:2.25.0'
    compile 'org.seleniumhq.selenium:selenium-chrome-driver:2.25.0'
}

I think problem is not in pattern. Problem in

task bugTests

:frowning: