在并行测试的情况下混淆 TeamCity 中的构建日志

Confusing Build log in TeamCity in case of parallel tests

我在本地主机上使用 Java、Gradle、TestNG、Selenium Hub 和 Node 并尝试运行 5 个并行测试,以下是示例代码。

这是基地 class:

package tests.temp;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class TestBase
{

protected ThreadLocal<RemoteWebDriver> threadDriver = null;

@BeforeMethod
public void setUp() throws MalformedURLException {

    threadDriver = new ThreadLocal<RemoteWebDriver>();
    DesiredCapabilities dc = new DesiredCapabilities();
    FirefoxProfile fp = new FirefoxProfile();
    dc.setCapability(FirefoxDriver.PROFILE, fp);
    dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
    threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
}

public WebDriver getDriver() {
    return threadDriver.get();
}

@AfterMethod
public void closeBrowser() {
    getDriver().quit();

}

}

这里是1个测试的例子。其他测试相同,除了名称和数字:

package tests.temp;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

public class Test01 extends TestBase
{

@Test
public void testLink()throws Exception
{

    getDriver().get("http://www.yandex.ru");
    WebElement textBox = getDriver().findElement(By.name("text"));
    textBox.sendKeys("First test");
    System.out.println("First test thread-count=\"1\"");

}

}

一个 XML-Suite 文件,包含所有这 5 个测试:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test runs" parallel="tests" thread-count="1">

<test name="Test_01">
    <classes>
        <class name="tests.temp.Test01" ></class>
    </classes>
</test>

 ...

<test name="Test_05">
    <classes>
        <class name="tests.temp.Test05" ></class>
    </classes>
</test>

</suite>

最后一个 - XML- 带有 Suite 运行ner 的文件:

<suite name="Parallel Test Suite">
<suite-files>
    <suite-file path="./testRunner.xml" />
</suite-files>
</suite>

问题是:如果我使用 thread-count="1",TeamCity 中的构建日志看起来不错,但当然要按顺序测试 运行s。 TeamCity thread = 1

如果 thread-count="2" 或任何其他值 - 构建日志看起来很混乱并且测试计数器值不正确。但是在 IDEA 中 - 一切都很酷而且正确! TeamCity thread = 2

有谁知道怎么解决这个麻烦吗??

如果您并行报告测试 运行,您应该分配它们 flowId,以便 TeamCity 了解哪个消息属于哪个测试。如果没有 flowId,不仅构建日志,而且测试统计也会不正确。如果没有 flowId,TeamCity 也可能错误地将测试标记为失败,即使其他测试报告了此失败。 至于在构建日志中正确显示并行测试,请参阅 TeamCity 跟踪器中的请求:https://youtrack.jetbrains.com/issue/TW-8249。请为它投票。