テスト部第6回MTG(Android)ã§ç¥ã£ãRobolectricã試ãã¦ã¿ããã¨ãEclipse Quick Start | Robolectricãè¦ãªãã試ãã¦ã¿ã¾ããããç§ã®è±èªåã®ä½ãã«ããï¼ï¼ï¼ãã¾ããããªãã£ãã®ã§ããã£ããã¨æ訳ããªãã試ãã¦ã¿ã¾ãã
ä¸æºå
Downloads | Robolectricãã robolectric-X.X.X-all.jar ããã¦ã³ãã¼ããã¦ããã¾ãã
robolectric-X.X.X.jar ããã¦ã³ãã¼ãããã¨ç§ã®ããã«æ®å¿µãªçµæã«ãªã£ã¦ãã¾ãã¾ãã
Androidããã¸ã§ã¯ãã®ä½æ
æ°è¦Androidããã¸ã§ã¯ãã®ãã¤ã¢ãã°
- ããã¸ã§ã¯ãåï¼MyProject
- ãã«ãã»ã¿ã¼ã²ããï¼ã¿ã¼ã²ããå: âGoogle APIsâ, ãã³ãã¼: âGoogle Inc.â, ãã©ãããã©ã¼ã â2.2â, Apiã¬ãã«: â8â
- ã¢ããªã±ã¼ã·ã§ã³åï¼MyProject
- ããã±ã¼ã¸åï¼com.example
- ã¢ã¯ãã£ããã£ã¼ã®ä½æï¼MyActivity
- æå°SDKãã¼ã¸ã§ã³ï¼8
- æå¾ã«å®äºãæ¼ã(ãã¹ãããã¸ã§ã¯ãã¯ä½æããªã)
ãã¹ãç¨ã½ã¼ã¹ãã£ã¬ã¯ããªã追å
- ããã±ã¼ã¸ã¨ã¯ã¹ããã¼ã©ã®âMyProjectâã§å³ã¯ãªãã¯ãã¦ãæ°è¦âãã©ã«ãã¼(ã½ã¼ã¹ã»ãã©ã«ãã¼ãä½æããªããã¨)
- ãã©ã«ãã¼åï¼test
- å®äºãæ¼ã
ãã¹ãç¨ã®Javaããã¸ã§ã¯ãä½æ
ãã¹ãç¨Javaããã¸ã§ã¯ãã®ä½æã¨è¨å®
- ãã¡ã¤ã«âæ°è¦âJavaããã¸ã§ã¯ã
- ããã¸ã§ã¯ãåï¼MyProjectTest
- 次ã¸ãæ¼ã
- MyProjectTestãå±éãã¦ããã®ä¸ã«ããâsrcâãé¸æ
- ãã½ã¼ã¹ã»ãã©ã«ãã¼ 'src' ããã«ãã»ãã¹ããé¤å»ãã®ãªã³ã¯ãã¯ãªãã¯
- ã追å ã½ã¼ã¹ã®ãªã³ã¯ããã¯ãªãã¯
- åç §ãã¿ã³ãæ¼ãã¦ãâ..\MyProject\testâãé¸æ
- å®äºãã¿ã³ãæ¼ã
ãã¹ãç¨ããã¸ã§ã¯ãã«jarãã¡ã¤ã«ã追å
ã¨ã¯ã¹ããã¼ã©ã§ãã³ãã³ãã©ã¤ã³ã§ãããã®ã§ã
- MyProjectTest ã®ä¸ã« lib ãã£ã¬ã¯ããªãä½æãã
- lib ãã£ã¬ã¯ããªã«
robolectric-X.X.X-jar-with-dependencies.jarrobolectric--X.X.X-all.jar ãã³ãã¼ãã
ãã«ããã¹ã®è¨å®
Eclipseã«æ»ã
- âMyProjectTestâã§å³ã¯ãªãã¯
- âãªãã¬ãã·ã¥âãé¸æï¼libãã©ã«ãã表示ãããï¼
- âMyProjectTestâã§å³ã¯ãªãã¯
- âãã«ããã¹âãé¸æââãã«ãã»ãã¹ã®æ§æâ
JUnitã©ã¤ãã©ãªã®è¿½å
- âã©ã¤ãã©ãªã¼âã¿ããé¸æ
- âã©ã¤ãã©ãªã¼âã®è¿½å
- âJUnitâãé¸æ
- â次ã¸âãã¯ãªãã¯
- âJUnit4âãé¸æ(Robolectric 㯠JUnit3 ã¨äºææ§ããªã)
- âå®äºâãã¯ãªã㯠(MyProjectTestã®ããããã£ã¼ã¯éããã¾ã¾)
Robolectric ã® jar ã追å
- âJar 追å âãã¯ãªãã¯
- MyProjectTest â lib ãå±é
robolectric-X.X.X-jar-with-dependencies.jarrobolectric--X.X.X-all.jar ãé¸æ- âOKâãã¯ãªã㯠(MyProjectTestã®ããããã£ã¼ã¯éããã¾ã¾)
Android ã® jar ã追å
- âå¤é¨ Jar 追å âãã¯ãªãã¯
\platforms\android-8\android.jar ãé¸æ - âéãâãã¯ãªã㯠(MyProjectTestã®ããããã£ã¼ã¯éããã¾ã¾)
- âå¤é¨ Jar 追å âãã¯ãªãã¯
\add-ons\addon_google_apis_google_inc_8\libs\maps.jar ãé¸æ - âéãâãã¯ãªã㯠(MyProjectTestã®ããããã£ã¼ã¯éããã¾ã¾)
- MyProjectTestããããã£ã¼ã®âOKâãã¯ãªãã¯
ãã¹ãã®å®è¡è¨å®
- âå®è¡â â âå®è¡æ§æâ
- âJUnitâãããã«ã¯ãªã㯠(âAndroid JUnit Testâã§ã¯ãªãã®ã§æ³¨æ)
- åå: MyProjectTestConfiguration
- âé¸æãããããã¸ã§ã¯ããããã±ã¼ã¸ãã¾ãã¯ã½ã¼ã¹ã»ãã©ã«ãã¼å ã®ãã¹ã¦ã®ãã¹ããå®è¡âã®ã©ã¸ãªãã¿ã³ãé¸æ
- âæ¤ç´¢ãã¿ã³âãã¯ãªãã¯
- âMyProjectTestâãé¸æ
- ãã¹ãã»ã©ã³ãã¼ï¼JUnit 4
- âè¤æ°ã®ã©ã³ãã£ã¼ã使ç¨å¯è½ã§ãâã®âä¸ã¤é¸æâãã¯ãªãã¯ãã
- âæ§æåºæã®è¨å®ã使ç¨âããã§ãã¯
- âEclipse JUnit ã©ã³ãã£ã¼âãé¸æ
- âOKâãã¯ãªãã¯
- âå¼æ°âã¿ããã¯ãªãã¯
- âä½æ¥ãã£ã¬ã¯ããªã¼:âã®ä¸ã«ããâãã®ä»:âãé¸æãã
- âã¯ã¼ã¯ã¹ãã¼ã¹âãã¯ãªãã¯
- âMyProjectâãé¸æï¼âMyProjectTestâã§ã¯ãªããã¨ãã£ããããã¯ã¹ã®ä¸ã¯â${workspace_loc:MyProject}âã«ãªãï¼
- âé©ç¨âãã¯ãªãã¯
- âéããâãã¯ãªãã¯
ã»ããã¢ããã®æ¤è¨¼
- âMyProjectTestâé ä¸ã®âtestâãã©ã«ãã¼ã§å³ã¯ãªãã¯
- âæ°è¦ââ âã¯ã©ã¹â
- ããã±ã¼ã¸ï¼âcom.exampleâ
- ååï¼âMyActivityTestâ
- âå®äºâãã¯ãªãã¯
- ä¸è¨ã½ã¼ã¹ã追å :
package com.example; import com.example.MyActivity; import com.example.R; import com.xtremelabs.robolectric.RobolectricTestRunner; import org.junit.Test; import org.junit.runner.RunWith; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @RunWith(RobolectricTestRunner.class) public class MyActivityTest { @Test public void shouldHaveHappySmiles() throws Exception { String hello = new MyActivity().getResources().getString(R.string.hello); assertThat(hello, equalTo("Hello World, MyActivity!")); } }
ãã¹ãã®å®è¡
- âå®è¡â â âå®è¡æ§æâ
- âJUnitâ â âMyProjectTestConfigurationâãé¸æ
- âå®è¡âãã¯ãªãã¯
å®è¡çµæ
java.lang.NoClassDefFoundError: javassist/Loader
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at com.xtremelabs.robolectric.RobolectricTestRunner.isInstrumented(RobolectricTestRunner.java:137)
at com.xtremelabs.robolectric.RobolectricTestRunner.(RobolectricTestRunner.java:86)
at com.xtremelabs.robolectric.RobolectricTestRunner.(RobolectricTestRunner.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: javassist.Loader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 33 more
ãªãã§ãããã»ã»ã»
ã¨ããããåãã¦ã¿ã
java.lang.NoClassDefFoundError: javassist/Loader ã°ã³ãã¼ã
@nakaji æ¥æ¬èªã§ãï½
2011-07-06 00:26:24 via TweetDeck to @nakaji
@AnotherSpooky ã¸ãã·ã¿ã¼
2011-07-06 00:26:46 via Tween to @AnotherSpooky
@nakaji ãªã«ãã¦ããã§ãï¼
2011-07-06 00:27:04 via YoruFukurou to @nakaji
@AnotherSpooky ããã§ãã¼ URL JavaVMã§åãAndroidç¨ã®ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯
2011-07-06 00:28:41 via Tween to @AnotherSpooky
@nakaji ãããã¨ãã¥ã¬ã¼ã¿ä½¿ããã«ãã¹ããããã£ã¦ãããã¬ã¼ã ã¯ã¼ã¯ã§ãããªï¼è¨å®ã¨ãã§ã¯ã¾ã£ã¦ãã£ã½ããã§ãï¼
2011-07-06 00:33:14 via TweetDeck to @nakaji
@AnotherSpooky ããµãµãQuickStartã®éãã«è©¦ããã ããªãã§ããã©ãjava.lang.NoClassDefFoundErrorã«ãªã£ã¡ãããã§ãï¼ï¼
2011-07-06 00:34:11 via Tween to @AnotherSpooky
@nakaji åç´ã«ã¯ã©ã¹è¦ãã¦ãªãã ãã ã¨æãã®ã§ãè¨å®å¨ããtypoãã¦ããã¨ãã§ãããªã¼
2011-07-06 00:35:35 via YoruFukurou to @nakaji
@AnotherSpooky ãã¡ã£ã¨ããè¦ã¦ã¿ã¾ãããããã¨ã§ãã¼
2011-07-06 00:37:19 via Tween to @AnotherSpooky
@nakaji ãµã³ãã«ããã¸ã§ã¯ãã¨ããããããã§ããã©ããã¡ãã¯åãã¦ã¾ãï¼
2011-07-06 01:01:33 via TweetDeck to @nakaji
@AnotherSpooky ããã¾ã 試ãã¦ãªãã§ã^^ï¼
2011-07-06 01:03:08 via Tween to @AnotherSpooky
@nakaji ãã¡ãã§ãã¡ããã¡ãã触ã£ã¦ã¿ãããã¨æã£ãã®ã§ãããMavenå¿ é ãããã®ã§æ¤é(ãдã)
2011-07-06 01:13:13 via TweetDeck to @nakaji
@AnotherSpooky ãã£ã¡ã¯Mavenããããããããæ¤éï½
2011-07-06 01:13:58 via Tween to @AnotherSpooky
ãªãã»ã©ãå ¨ãããããããã
@AnotherSpookyããããã¤ãããé ããããã¨ããããã¾ããã
æå¾ã«
ãµã¨ã°ã°ã£ã¦ã¿ã¾ããã
ã§ããã®æãã¦ã³ãã¼ãããjarã«ç½ ããã£ã¦ãæå robolectric-0.9.2.jar ã使ã£ã¦ãããjavasisstã¨ãã®ã©ã¤ãã©ãªãå ¥ã£ã¦ãªãã¦ãã¾ãåãã¾ããã§ããã
robolectric-0.9.2-all.jar ããã§ãã£ã¡ãall ãã¤ãã¦ããæ¹ããã¦ã³ãã¼ããã¦ãããªãã¨æ¶ç®ã«ãªãã¾ãã
2010-11-27 - @vvakame の日記
ãªãããã ãã¨ãï¼
ã¨ããããã§ãæ©éç¾æç¹ã§ã®ææ°çãrobolectric-0.9.4-all.jarãããã¦ã³ãã¼ããã¦ãã«ããã¹ã®ã©ã¤ãã©ãªã¼ãå·®ãæ¿ãã
ããã¦å®è¡ãã¦ã¿ããã»ã»ã»
ã¡ããã¨åãã¾ããã