JUnit Test在执行时抛出ClassNotFoundExcpetion

时间:2016-07-07 15:17:27

标签: java eclipse junit appium

我试图在Eclipse中使用Junit为Android应用编写一个简单的Appium测试。以下是我的代码。

@Test
    public void test() throws MalformedURLException{
        AndroidDriver<MobileElement> driver;        
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
        cap.setCapability(MobileCapabilityType.APP, "C:\\Automation\\ExpediaHotelsFlightsCarsv6.10.0.apk");
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM);
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
        ***driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);***
        driver.launchApp();
    }

我在

行运行测试时遇到以下错误

driver = new AndroidDriver(新网址(&#34; http://127.0.0.1:4723/wd/hub&#34;),上限);

  

java.lang.NoClassDefFoundError:com / google / common / base / function at   AppiumTest.test(AppiumTest.java:37)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     在   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)     在   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     在   org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)     在   org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)     在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)     在   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at at   org.junit.runners.ParentRunner.run(ParentRunner.java:363)at at   org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     在   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)   引起:java.lang.ClassNotFoundException:   com.google.common.base.Function at   java.net.URLClassLoader.findClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)at   sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)... 26更多

请帮我解决此问题,并了解解决方案。

谢谢, KK

1 个答案:

答案 0 :(得分:0)

请确保您已在pom或构建路径中添加了selenium的所有依赖项。你的pom必须低于jar,

selenium-server-standalone-XXX.jar
selenium-java-XXX.jar.