实例化类时出错:class:null java.lang.reflect.InvocationTargetException

时间:2015-06-10 15:19:48

标签: java eclipse junit jmeter

使用Selenium JUnit Java + JMeter进行负载测试。

在Eclipse中开始测试,一切正常,在创建一个JAR文件并将其放在apache / lib / junit目录中后,启动JMeter选择这个JAR文件,它崩溃了,出错了。我在stackoverflow和其他siter上阅读了很多答案,但没有找到任何可以帮助我的答案。

这是日志:

2015/06/10 18:10:41 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
2015/06/10 18:10:49 ERROR - jmeter.protocol.java.sampler.JUnitSampler: Error instantiating class:class LoadTestGuppy.LoadTestGuppy.AppTest:null java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

和代码:

package LoadTestGuppy.LoadTestGuppy;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

import junit.framework.TestCase;


public class AppTest extends TestCase {
    private WebDriver driver = new FirefoxDriver();

    public AppTest(){}

    public AppTest(String text){
        super(text);
    }

    @Before
    public void setUp() throws Exception {
        driver.get("http://barracuda-qa.ko.kodak.com/d2l/faces/Login.jsp");
        driver.manage().window().maximize();
    }

    @Test
    public void testTestLoad() throws Exception {
        driver.findElement(By.id("loginForm:authLogin")).sendKeys("some222");
        driver.findElement(By.id("loginForm:authPassword")).sendKeys("222");
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.findElement(By.id("loginForm:btnLogin")).click();
        driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//a[@class='log']")).click();
        driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//a[@class='logout']")).click();

    }

    @After
    public void tearDown() throws Exception {
        driver.close();
    }

}

它可以是什么?

2 个答案:

答案 0 :(得分:0)

尝试删除这些

InvocationTargetException是一个经过检查的异常,它包装了被调用的方法或构造函数抛出的异常

public AppTest(){}

        public AppTest(String text){
            super(text);
        }

您可以尝试重新安装jar文件,看看是否有效

答案 1 :(得分:0)

Have you added Selenium jars into JMeter's /lib folder? If not - copy them there, restart JMeter and retry.

By the way, there is WebDriver Sampler这对于Selenium和JMeter集成来说可能更方便。

如果您决定采用JUnit方式,我建议将调试命令行参数添加到JMeter启动脚本,例如

set JVM_ARGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 %JVM_ARGS%

之后,您可以使用Eclipse连接到JMeter JVM实例,究竟是什么“null”并解决它。有关JMeter和Eclipse端的更多线索和确切配置说明,请参阅How to debug your Apache JMeter script指南。