使用Gatling

时间:2015-06-04 12:06:44

标签: scala gatling

我想清理我的代码结构,并将类/目标文件放在我的gatling项目的另一个目录中。

如果我将所有模拟类和utils类放在同一目录和相同的包中,我不需要import语句,一切正常。

假设我的结构如下:

/user-files
----/simulations
--------MySimulation.scala
----/utils
--------Router.scala

我尝试了几种导入或命名配置,以便能够在我的模拟中使用路由器。

  1. 将包命名作为目录结构
  2. 将模拟和工具类放在同一个包中
  3. 我也尝试了不同的导入方式

    //using package
    import packagename.Router
    
    //another try
    import packagename.Router._
    
    //without package name
    import Router._
    

    我尝试在scala文档或堆栈溢出上搜索解决方案并没有帮助我。

    这是执行gatling.bat

    后给出的错误
    not found: value Router
    

1 个答案:

答案 0 :(得分:1)

你不能这样做:有一个单一的源文件夹,默认为/user-files/simulations

如果你想使用文件夹/包(这是一件好事),你可以拥有如下结构:

/user-files
----/simulations
--------MySimulation.scala
--------/utils
------------Router.scala

然后,在Scala中,包和文件夹层次结构不相关,但是使用与Java相同的约定是一种很好的做法。

所以,你会:

package utils
object Router

然后在MySimulation中:

import utils.Router