我做了一个金牛座测试说明:
execution:
- executor: junit
iterations: 5 # loop over test suite for 5 times
concurrency: 20 # number of virtual users
ramp-up: 1m # time of load growing
steps: 5 # number of steps of growing
scenario:
script: src/test
modules:
junit:
junit-version: 5
working-dir: src/main/java
我的单元测试是:
package org.steinko.springtutorial;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.steinko.springtutorial.Main;
public class MainTest {
@Test
void shouldReturnANumber(){
Main main = new Main();
String[] arg = new String[1];
Main.main(arg);
int number = main.getNumber();
assertTrue(0 < number);
assertTrue(number < 100);
}
}
我的源代码位置是:
package org.steinko.springtutorial;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.steinko.springtutorial.NumberGenerator;
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
private static int number;
private static final String CONFIG_LOCATION = "beans.xml";
public static void main(String[] args )
{
log.info("Guess the number game");
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATION);
NumberGenerator numberGenerator = context.getBean("numberGenerator", NumberGenerator.class);
number = numberGenerator.next();
log.info("number = {}", number);
context.close();
}
public int getNumber() {
log.info("getNumber",number);
return number;
}
}
当我运行 bzt ./performnctests/unittests.yaml 时出现错误:
[2019-03-17 15:34:25,556 ERROR root] 子进程错误:Javac 退出,代码:1
/Users/stein/Development/guess-the-number-game/core/src/test/java/org/steinko/springtutorial/MainTest.java:7:错误:找不到符号
导入 org.steinko.springtutorial.Main;
^
符号:主类
位置:包 org.steinko.springtutorial
/Users/stein/Development/guess-the-number-game/core/src/test/java/org/steinko/springtutorial/MainTest.java:15:错误:找不到符号
Main main = new Main(); ^
符号:主类
位置:类 MainTest
/Users/stein/Development/guess-the-number-game/core/src/test/java/org/steinko/springtutorial/MainTest.java:15:错误:找不到符号
Main main = new Main(); ^
符号:主类
位置:类 MainTest
/Users/stein/Development/guess-the-number-game/core/src/test/java/org/steinko/springtutorial/MainTest.java:17:错误:找不到符号
Main.main(arg); ^
符号:变量 Main
位置:类 MainTest
4 个错误
如何修复此错误?