JUnit test in Android Studio: NoClassDefFoundError: junit/textui/ResultPrinter - exception

I have a fresh installation of Android Studio with a new Android project. I created one JUnit test class but I cannot run it:
"C:\Program Files\Java\jdk1.7.0_55\bin\java" -ea -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files\android-studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\android-studio\lib\idea_rt.jar;C:\Program Files\android-studio\plugins\junit\lib\junit-rt.jar;D:\Dev\android-sdks\platforms\android-21\android.jar;D:\Dev\android-sdks\platforms\android-21\data\res;D:\Dev\android-sdks\tools\support\annotations.jar;d:\myapp\mobile\build\intermediates\classes\debug;D:\jon\.gradle\caches\modules-2\files-2.1\com.j256.ormlite\ormlite-android\4.48\afa06f539a4026c10b247386312aa67404b80a16\ormlite-android-4.48.jar;D:\jon\.gradle\caches\modules-2\files-2.1\commons-io\commons-io\2.0.1\7ffdb02f95af1c1a208544e076cea5b8e66e731a\commons-io-2.0.1.jar;D:\Dev\android-sdks\extras\android\m2repository\com\android\support\support-annotations\21.0.2\support-annotations-21.0.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.j256.ormlite\ormlite-core\4.48\e579bd2905d0399af5029aaaf9817d5fa0ca88a5\ormlite-core-4.48.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\res;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\libs\internal_impl-21.0.2.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\classes.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger\1.2.2\e8f912ee19ad84958510883ea191135276b091f8\dagger-1.2.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject\1\6975da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;D:\jon\.gradle\caches\modules-2\files-2.1\org.androidannotations\androidannotations-api\3.2\89b33bb1e996eb2c4089f79d1b8651c71fe8e2d1\androidannotations-api-3.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.squareup\otto\1.3.5\7941cd2c2c8ec006800d75c35f8a9dacf892ab93\otto-1.3.5.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.71\classes.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.71\res;d:\myapp\mobile\build\intermediates\exploded-aar\net.danlew\android.joda\2.5.1\classes.jar;d:\myapp\mobile\build\intermediates\exploded-aar\net.danlew\android.joda\2.5.1\res;D:\jon\.gradle\caches\modules-2\files-2.1\org.robobinding\robobinding\0.8.9\c6b50ddd9e741a7c8e54b56ac7057a66312a3e11\robobinding-0.8.9-with-dependencies.jar;d:\myapp\javamail\build\intermediates\classes\debug" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.example.MyUnitTest
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
It's my first attempt to use Android Studio and to do JUnit tests. So sorry if the solution is obvious.

Following solution worked for me in windows:
1) in the environment variables add a new "system variables"
ANDROID_SDK_HOME=D:\Program Files\android-sdk-windows (select your home directory of android sdk )
2) modify system variables Path, add "%Android_SDK_HOME%\tools;"

Related

junit manipulation filter not found in eclipse

I have setup my test in /src/test/bdd/integration/java folder, when I try to run my test I get
java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:380)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:224)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:208)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.manipulation.Filter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
I guess your project is not maven based.
Run -> Run Configurations
Open the tab "Classpath", click the button "Advanced..." on the left
Select "Add Library" --> Junit
Then, under the 'User Entries', you will see the Junit library.

Cucumber test results with CucumberException: Failed to instantiate public

I am getting this error:
cucumber.runtime.CucumberException: Failed to instantiate public
cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader)
with [cucumber.runtime.io.MultiLoader#7006c658] at
cucumber.runtime.Reflections.newInstance(Reflections.java:44) at
cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:30)
at cucumber.runtime.Runtime.loadBackends(Runtime.java:98) at
cucumber.runtime.Runtime.<init>(Runtime.java:65) at
cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78) at
cucumber.api.junit.Cucumber.<init>(Cucumber.java:58) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source) at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at
org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
Below are the jars I have in my build path:
cucumber core 1.2.4
cucumber java 1.1.3
cucumber junit 1.2.4
cucumber jvm deps 1.0.5
cucumber html 0.2.2
cucumber reporting 2.2.0
gherkin 2.12.2
selenium java 2.53.0
selenium server
standalone > 2.53.1
That looks like some dependencies mismatch. Generally, you need these to run Cucumber in Java:
cucmber-junit
cucumber-java
junit
I see that you already have cucumber-html in your list. Try to remove it and see if that helps. Also, make sure you don't have other unneeded dependencies that can be removed.

Legacy Maven 2 job type Plugin with Maven 3.2.1 not working

I try to use Hudson (3.3.3) and Legacy Maven 2 job type Plugin (3.0.2) with Maven (3.2.1), but I get an error. Is there a way to use Maven 3.2.1?
Job log:
Found mavenVersion 3.2.1 from file jar:file:/C:/Users/dur/.hudson/tools/Maven_3.2.1/lib/maven-core-3.2.1.jar!/META-INF/maven/org.apache.maven/maven-core/pom.properties
Parsing POMs
[workspace] $ "C:\Program Files\Java\jdk1.7.0_25/bin/java" -cp C:\Users\dur\.hudson\plugins\maven-plugin\WEB-INF\lib\maven3-agent-3.0.2.jar;C:\Users\dur\.hudson\tools\Maven_3.2.1\boot\plexus-classworlds-2.5.1.jar org.jvnet.hudson.maven3.agent.Maven3Main C:\Users\dur\.hudson\tools\Maven_3.2.1 C:\Users\dur\.hudson\war\webapp\WEB-INF\lib\hudson-remoting-3.0.3.jar C:\Users\dur\.hudson\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-3.0.2.jar 61659
<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven: -B -f C:\Users\dur\.hudson\jobs\Test\workspace\pom.xml clean install -P Hudson
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:146)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:124)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:71)
at hudson.remoting.UserRequest.perform(UserRequest.java:107)
at hudson.remoting.UserRequest.perform(UserRequest.java:41)
at hudson.remoting.Request$2.run(Request.java:276)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/cli/MavenLoggerManager
at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:73)
... 18 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.cli.MavenLoggerManager
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
... 19 more
channel stopped
I found following questions:
Eclipse Community Forums
GitHub
User list for the Hudson continuous build server
but with no working answer.
I found a work-around with Hudson (3.3.3) free-style project and Maven 3 Build Plugin (3.0.5):
Maven 3 Build Plugin configuration (see Hudson Book):
Build Step configuration (see Hudson Book):

Can't run Chrome from Jenkins with Cygwin

I'm testing JsTestDriver with Jenkins locally on Windows XP with Cygwin (at the front of my system Path).
Jenkins calls a .sh script which contains the following:
java -jar "D:\Tools\jstestdriverexample\JsTestDriver-1.3.4.b.jar" --port 9876 --server http://localhost:9876 --tests all --reset --config jsTestDriver-Jasmine.conf --testOutput results-jasmine --browser "C:/Program Files/Internet Explorer/iexplore.exe","C:/Program Files/Mozilla Firefox/firefox.exe","C:\Documents and Settings\alynch\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"
When Google Chrome is included, the Jenkins job stalls and I eventually get this error in the console output:
Failures during test run.
Caused by:
Tried 1times:
com.google.jstestdriver.util.RetryException:
Failure 1: java.lang.NullPointerException
at com.google.jstestdriver.util.RetryingCallable.call(RetryingCallable.java:62)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown
at java.util.concurrent.FutureTask.run(Unknown
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.google.jstestdriver.browser.CommandLineBrowserRunner.stopBrowser(CommandLineBrowserRunner.java:94)
at com.google.jstestdriver.browser.BrowserControl.stopBrowser(BrowserControl.java:148)
at com.google.jstestdriver.browser.BrowserCallable.call(BrowserCallable.java:30)
at com.google.jstestdriver.util.RetryingCallable.call(RetryingCallable.java:49)
... 10 more
at com.google.jstestdriver.browser.BrowserActionExecutorAction.run(BrowserActionExecutorAction.java:154)
at com.google.jstestdriver.ActionRunner.runActions(ActionRunner.java:81)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342)
at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233)
at com.google.jstestdriver.Main.main(Main.java:70)
Caused by:
Tried 1times:
com.google.jstestdriver.util.RetryException:
Failure 1: java.lang.NullPointerException
If I try to run Google Chrome in Cygwin it works but I get the following message:
[5424:5192:3977000:ERROR:gpu_info_collector_win.cc(90)] Can't retrieve a valid WinSAT assessment.
Is the problem that I'm running Jenkins as a Windows service and it can't run Chrome because it needs to run as me (my user profile)?
The symptoms indeed point to running Jenkins as a service as the problem. To find out if that's indeed the case run Jenkins in the foreground:
java -jar jenkins.war <other options>
You can find the list of common options here.

Play Framework, WARs and Tomcat 6 deployment exception

I've created a Play 1.2.3 app and I'm trying to deploy its war file to Tomcat 6, but I keep getting this exception.
I generate the war file, enabling the "production" profile, with:
play war webapp -o webapp.war --%production --zip
I get two files:
A webapp.war folder
A webapp.war.war file
I move the webapp.war.war file into the webapps folder of Tomcat, renaming the file to webapp.war. When I start Tomcat and try to execute the app, the following exception appears:
SEVERE: Exception sending context initialized event to listener instance of class play.server.ServletWrapper
java.lang.NullPointerException
at play.classloading.ApplicationClassloader.scanPrecompiled(ApplicationClassloader.java:527)
at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:385)
at play.Play.preCompile(Play.java:550)
at play.Play.init(Play.java:291)
at play.server.ServletWrapper.contextInitialized(ServletWrapper.java:74)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Any tips?
run this
play war webapp -o temp --%production --zip
after you get the temp.war, rename it into webapp.war, then deploy
HTH