gpt4 book ai didi

java - 在不同的测试中使用相同的字符串时出错

转载 作者:行者123 更新时间:2023-12-02 16:31:18 25 4
gpt4 key购买 nike

我有以下场景:我在 Cucumber、Selenium Webdriver、Java 中执行了几个测试 (@Test) 和测试。

测试进行得很顺利。 但是,我想将存储在一个@Test(公共(public)无效)中的字符串保留在另一个@Test(公共(public)无效)中。我不能。

有人能帮忙吗?

第一次测试:

@Test
public void testDocuments() {
OneClass oneClass = new OneClass();
oneClass.one();
oneClass.two();
}

第二次测试:

@Test
public void testDocuments() {
OneClass oneClass = new OneClass();
oneClass.one();
oneClass.two();
}

方法一

public String one() {
if (this.cnpj == null) {
this.cnpj = add.cnpj(false);
} else {
}
return this.cnpj;
}

这两个测试我希望你使用相同的生成字符串!!!!

我期待并提前致谢!

最佳答案

我不确定你的方法 one() 做了什么,但假设你想对两个不同的测试使用相同的值,为什么不这样做:

OneClass oneClass = new OneClass();
String yourGeneratedString = oneClass.one();

// First test

@Test
public void testDocuments() {
yourFunction(yourGeneratedString);
}

// Second test

@Test
public void testDocuments2() {
yourOtherFunction(yourGeneratedString);
}

关于java - 在不同的测试中使用相同的字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63453823/

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