0

我做了一个金牛座测试说明:

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 个错误

如何修复此错误?

4

1 回答 1

0

这似乎是您试图在您的 java 类中使用外部依赖项。Taurus 在尝试编译之前并没有完全构建模块。因此,您的项目在类路径中的任何依赖项都不会被识别。对此的解决方案是将依赖项作为 .jar 文件与 BZ 测试中的 .java 文件一起上传。基本上,您在测试脚本中导入的任何类/接口都应作为 jar 提供。所以你的配置文件看起来像这样:


  - 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

      additional-classpath: # just an example - you can include your own .jar files
       - rest-assured-2.9.0.jar
       - log4j-1.2.17.jar
       - groovy-2.4.4.jar
       - rest-assured-common-2.9.0.jar
       - json-path-2.9.0.jar

modules:

  junit:

    junit-version: 5

    working-dir: src/main/java

更多详细信息,请访问https://gettaurus.org/docs/JUnit/

于 2019-08-27T15:57:08.503 回答