gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:36:12 26 4
gpt4 key购买 nike

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

这是基类:

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 文件,包含所有这 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>

最后一个 - 带有 Suite runner 的 XML 文件:

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

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

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

谁知道怎么解决这个问题??

最佳答案

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

关于java - 在并行测试的情况下混淆 TeamCity 中的构建日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37873925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com