English 中文(简体)
测试班与测试阶段的@Factory平行
原标题:Running test classes in parallel with @Factory in TestNG

共有5个测试班。 每一数据均采用@Factory(数据提供人=“数据”)进行初步编制。 我想要达到的是,每一试验类别中的测试方法应与数据提供方平行运行。 此外,测试班应当同时进行。

Something like the following. TestClass1 should be running the dataprovider instances in parallel. So, all the methods of test class TestClass1 will be running in parallel for the dataprovider instances.

此外,与测试Class1一样,还有2个其他测试班。 我期待他们采取同样的行动,所有3个测试班同时运行。

测试纳克.xml的测试级和参数安排下

data-provider-thread-count="10" parallel="instances" thread-count="5""

a. 在适当和测试一级,

parallel=“instances”thread-count=”5"

观察到的行为是,由数据提供人所引发的测试Clas1 事件同时发生。 测试Class2和测试Class3尚未开始执行。 在测试Class1结束后不久,测试Class2开始采用与测试Class1相同的方式执行,随后是测试Class3。

我需要做些什么改变才能达到预期行为。

提前感谢。

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.reporters.EmailableReporter2;

@Listeners({ TestExecutionListener.class, EmailableReporter2.class })
public class TestClass {

    private int value;

    @Factory(dataProvider = "data", dataProviderClass = TestClass.class)
    public TestClass(final int value) {
        this.value = value;
    }

    @Test(alwaysRun = true)
    public void testOdd() {
        Assert.assertTrue(value % 2 != 0);
    }

    @Test(alwaysRun = true)
    public void testEven() {
        Assert.assertTrue(value % 2 == 0);
    }

    @DataProvider(name = "data")
    public static Iterator<Object[]> data() {

        List<Object[]> list = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            list.add(new Object[] { i });
        }
        return list.iterator();
    }
}

测试纳克.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="mobile rc automation suite"
    data-provider-thread-count="10" parallel="instances" thread-count="5">

    <test name="test_1" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass1" />
        </classes>
    </test>

    <test name="test_2" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass2" />
        </classes>
    </test>

    <test name="test_3" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass3" />
        </classes>
    </test>

</suite>
问题回答

最后,我能够开办“Factory”测试班,这些试验班在“设计”;测试/设计;同时使用特定的测试NG×ml。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="mobile rc automation suite"
    data-provider-thread-count="10" parallel="tests" thread-count="5">

    <test name="test_1" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass1" />
        </classes>
    </test>

    <test name="test_2" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass2" />
        </classes>
    </test>

    <test name="test_3" parallel="instances"
        thread-count="5">
        <classes>
            <class name="com.test.TestClass3" />
        </classes>
    </test>

</suite>

你们可以把它与“方法”相平行。 在测试一级消除平行的“情况”。 仅保持适当水平。

感谢。 我得以使用<代码>平行轨道=“instances”。

The XML:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="CommonSuite" configfailurepolicy="continue" parallel="instances" thread-count="2">
    <test name="MyTest">
        <classes>
            <class name=ParallelTestFactory">
            </class>
        </classes>
    </test>
</suite>
public class ParallelTest {
    public ParallelTest(String[] varName) {
        this.varName = varName;
    }
// imports
import testng.annotations.Factory;

public class ParallelTestFactory {
    private int i = 0;
    @Factory
    public Object[] createTest() {
        return new Object[] {
         new ParallelTest(ParallelTestConstants.var1), 
         new ParallelTest(ParallelTestConstants.var2)};
    }
}
public class ParallelTestConstants {
public String[] var1 = {"a","b","c"};
public String[] var2 = {"e","f","g"};
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签