2

我开始使用磨床工具,每当我运行我的脚本时,我都会收到以下错误。

ImportError: No module named net.grinder.script. Grinder

这是我要运行的脚本

# A minimal script that tests The Grinder logging facility.
#
# This script shows the recommended style for scripts, with a
# TestRunner class. The script is executed just once by each worker
# process and defines the TestRunner class. The Grinder creates an
# instance of TestRunner for each worker thread, and repeatedly calls
# the instance for each run of that thread.

  from net.grinder.script.Grinder import grinder
  from net.grinder.script import Test

# A shorter alias for the grinder.logger.info() method.
  log = grinder.logger.info

# Create a Test with a test number and a description. The test will be
# automatically registered with The Grinder console if you are using
# it.
  test1 = Test(1, "Log method")

# Instrument the info() method with our Test.
  test1.record(log)

# A TestRunner instance is created for each thread. It can be used to
# store thread-specific data.
 class TestRunner:

# This method is called for every run.
 def __call__(self):
    log("Hello World")

运行此脚本时,我会收到导入错误。

我也设置了 CLASSPATH 和 JAVA_HOME 环境变量。谁能帮我吗。

4

3 回答 3

1

设置类路径有点棘手,在运行上面 Philp 提供的 java 命令之前,我在 mac(10.6.8) 终端上做了以下操作:

类路径设置:(在终端上依次执行)

    export JAVA_VERSION=1.6
    export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    export GRINDERPATH=/Users/cdname/grinder-3.11
    export CLASSPATH=$GRINDERPATH/lib/grinder.jar:$CLASSPATH
    export PATH=$JAVA_HOME/bin:$PATH
    java -classpath $CLASSPATH net.grinder.Grinder

我将它包含在 /etc/launchd.conf 中,然后运行 ​​grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 启动ctl

在grinder.properties 文件集中:grinder.useConsole = false

现在运行 .py 文件:

     java -Dgrinder.script=csaTest.py net.grinder.Grinder
于 2014-09-04T14:11:11.223 回答
1

在我看来,您正在尝试使用 Jython 直接运行脚本。您应该使用 The Grinder 运行脚本。

如果您已正确设置类路径,并且脚本文件位于本地目录中并命名为helloworld.py,那么

java -Dgrinder.script=helloworld.py net.grinder.Grinder

应该启动一个代理,运行一个工作进程,然后执行一次你的脚本。

于 2014-05-05T14:18:07.113 回答
0

你能和我发布的详细信息交叉检查吗@

http://stackoverflow.com/questions/19148365/cant-run-grinder-java-test-framework/19429771#19429771

好像是路径问题。如果上述解决方案均无效,请尝试使用“sys.path()”手动设置路径并在示例 Jython 脚本中打印并将输出粘贴到此处

print sys.path
于 2014-05-05T07:15:52.810 回答