Jmeter - JUnit采样器

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (381)

我被困在这一点上。我成功多次使用过JUnit Sampler。但是这次我尝试运行简单的程序时遇到以下错误。

整个堆栈跟踪:

2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2014/11/05 16:27:23 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2014/11/05 16:27:23 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Thread will stop on error 
2014/11/05 16:27:23 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2014/11/05 16:27:23 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
**2014/11/05 16:27:23 INFO  - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)** 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Stop Thread detected by thread: Thread Group 1-1 
2014/11/05 16:27:23 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2014/11/05 16:27:23 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2014/11/05 16:27:23 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 

这是我的类:

package jmeter;

import java.io.File;    
import java.util.Iterator;    
import java.util.Set;    
import java.util.concurrent.TimeUnit;    
import org.apache.log4j.Logger;    
import org.junit.Before;    
import org.junit.BeforeClass;    
import org.junit.Test;    
import org.openqa.selenium.By;    
import org.openqa.selenium.WebDriver;    
import org.openqa.selenium.firefox.FirefoxDriver;

public class ShoppingCartTest {

  public  WebDriver driver=null;

  //Initializes/loads  the driver based on type of browser defined in config file
  @Before
  public void initDriver(){
      driver =new FirefoxDriver();
      driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void verifyAnItemToWishList() throws InterruptedException{
    driver.get("http://www.google.com")     
    System.out.println("done");

  } 
}   
提问于
用户回答回答于

我有类似的问题。它解决了下载新的Jmeter实例,安装Selenium / WebDriver Support插件和Selenium Server Standalone jar。所以这个错误可能只是因为在Jmeter Lib文件夹中没有需要Jar。

用户回答回答于

你的代码看起来不错,那里没有问题。确保满足以下条件:

  1. 你的类打包成.jar文件并放到你的JMeter安装的/ lib / junit文件夹中
  2. 寻找到你@Before@Test注解-你使用JUnit4。在这种情况下,需要Search for JUnit4 annotations在JUnit请求采样器中勾选如下所示的复选框:

所属标签

可能回答问题的人

  • 天使的炫翼

    17 粉丝531 提问9 回答
  • 优惠活动秘书

    0 粉丝2 提问8 回答
  • 最爱开车啦

    8 粉丝503 提问6 回答
  • 富有想象力的人

    3 粉丝0 提问5 回答

扫码关注云+社区

领取腾讯云代金券