All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.testing.testng.TestNGParallelSuiteIntegrationTest.groovy Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.gradle.testing.testng

import org.gradle.integtests.fixtures.DefaultTestExecutionResult
import org.gradle.integtests.fixtures.MultiVersionIntegrationSpec
import org.gradle.integtests.fixtures.TargetCoverage
import org.gradle.testing.fixture.TestNGCoverage
import spock.lang.Issue

@TargetCoverage({TestNGCoverage.STANDARD_COVERAGE})
public class TestNGParallelSuiteIntegrationTest extends MultiVersionIntegrationSpec {

    @Issue("GRADLE-3190")
    def "runs with multiple parallel threads"() {
        buildFile << """
            apply plugin: 'java'
            repositories { mavenCentral() }
            dependencies {
                testCompile 'org.testng:testng:$version'
            }
            test {
              useTestNG {
                suites "suite.xml"
              }
            }
        """

        String suiteXml = ""
        200.times { x ->
            file("src/test/java/Foo${x}Test.java") << """
                public class Foo${x}Test {
                    @org.testng.annotations.Test public void test() {
                        for (int i=0; i<20; i++) {
                            System.out.println("" + i + " - foo ${x} - " + Thread.currentThread().getId());
                        }
                    }
                }
            """
            suiteXml += "\n"
        }

        file("suite.xml") << """


  $suiteXml
"""


        when:
        run("test")

        then:
        def result = new DefaultTestExecutionResult(testDirectory)
        result.testClass("Foo0Test").assertTestsExecuted("test")
        result.testClass("Foo199Test").assertTestsExecuted("test")
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy