Libraryããã¸ã§ã¯ãã®ãã¹ã
Libraryãã¹ãã§ããã£ãã®ã§è¦æ¸
é常ã®Libraryããã¸ã§ã¯ããããã¹ãããã¸ã§ã¯ããä½æãã¦å®è¡ããã¨ã¨ã©ã¼ãçºçãã
Could not find XXX.apk!
ãã¹ãããã¸ã§ã¯ãã§ã¯apkãã¡ã¤ã«ãä½æãããªãã®ã§è¦ã¤ãããªãã£ã¦ã¨ã©ã¼ãèµ·ãã
調ã¹ãã¨developerãµã¤ãã«ã¯ã©ã¤ãã©ãªã®ãã¹ãæ¹æ³ãæ¸ããã¦ãã
http://developer.android.com/tools/projects/index.html#testing
Testing a Library Project There are two recommended ways of setting up testing on code and resources in a library project: You can set up a test project that instruments an application project that depends on the library project. You can then add tests to the project for library-specific features. You can set up a standard application project that depends on the library and put the instrumentation in that project. This lets you create a self-contained project that contains both the tests/instrumentations and the code to test.
è¦ç´ããã¨æ¹æ³ã¯2ã¤ãããã§ã©ã£ã¡ãé¸ãã§
# ã©ã¤ãã©ãªä½¿ã£ã¦ãã¢ããªã±ã¼ã·ã§ã³ã®ãã¹ãããã¸ã§ã¯ããä½æããã¨OK
# æ®éã®ããã¸ã§ã¯ãä½æãã¦testã±ã¼ã¹ã¨instrumentationså
¥ãã¨ãã¦
åè ã¯ã¢ããªã®ãã¹ãã§ä¸ç·ã«ã©ã¤ãã©ãªããã¹ããã¦ããã£ã¦ãã¨ããããããããªã®ã©ã¤ãã©ãªããã¸ã§ã¯ãã®æå³ãããªã
ãããããrâz´ããã/ ã ããããããï½ã½L_ ã ã ãã|/|/ã/ã/| ã|ãã ï¾ï½¤ ï¼¼ ï¼¼ã½ï¾ ï¼¼ ãããããV/|/|ã/â|ï¼|_,lã |_ï¼âã½| ï¾ï½¤|| ï¾ï½¤| ãããã ã¤|ï½²ã|/y'´ï¼.j`´|ï¼¼|´ï¾ï¼ï½'v|ï¾Nï½| |ããããã ãã«ã¡ï¼ ããããã|| |ã|⧠ã ã ãï½¥ ã ã ã/kï¼ ã| | ããããã|| |ã|ã½ï¾ãã ã ï¿£ï½|ããï½²-'|ãã| | å¥ã¢ããªã§ã©ã¤ãã©ãªãã¹ããªãã¦ãªãã¦ä¿¡ããããªã ããããã|| |ã|:|:|:|:lï¼¼. |_ããï¾.ï¼//:::|ãã| | ãã ã ã|{ï¼ï¿£ï¿£ï¼¼Â´ï¼¼ï¿£ 7/ ̄㴠̄\l.|ããã©ãèãã¦ãåºè¾ºããã°ã©ãã®çºæ³ã ã ãããã ï¾/ï½°ï¼âã½:.:.:ï¼¼ãï¼¼/ã.ï½²:.:.:.:.:/ï¼ï½¤| ã ã ã//ããã½::::ï¾:.:.:.:.:| ï¼Xãã|:.:.:.:.|ï¼ãï¼¼ ããã /ãã /ï¿£}::::::ï¼¼:.:.ï¾ï½¤/⧠.>|:.:.:.:.}â ãã ï¼¼ ããã { :}/´lã .::|ï¼::::: ̄ ̄ï½)ï¾ã|:.:.:./:::::ï¼ããã> ããã |Klã |..:::::ï¾ ï¼ï¿£|ï¿£/ã ./:.:./ï¼¼::::::::....ï¼ï¼¼
ãªã®ã§å¾è
ã®ææ³ã§ãã£ã¦ã¿ããããããè²ã
ã¨åé¡ãããããã¦å°ã
devãµã¤ããããå°ãããã¥ã¡ã³ãã詳ããããã»ããããã ã
ã©ã¤ãã©ãªããã¸ã§ã¯ãã®ãã¹ãããã¸ã§ã¯ãã®ä½ææ¹æ³
æé
- æ®éã«ã©ã¤ãã©ãªããã¸ã§ã¯ããä½æãã
- ãã¹ãããã¸ã§ã¯ããæ®éã®ã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã¨ãã¦ä½æãã
- ããã±ã¼ã¸ã¯ã©ã¤ãã©ãªã¨åä¸ã«ãã
- ãã¹ãããã¸ã§ã¯ãã«ã©ã¤ãã©ãªã追å
- Manifestã«instrumentationã¨uses-library追å
- TestCaseä½æ
æ®éã«ã©ã¤ãã©ãªããã¸ã§ã¯ããä½æãã
MyLibã¨ããã©ã¤ãã©ãªãä½æãã¦ãUtilã¯ã©ã¹ãä½æ
package com.example.lib; public class Util { public static String echo(String message){ return message; } }
ãã¹ãããã¸ã§ã¯ããæ®éã®ã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã¨ãã¦ä½æãã
ãã¹ãããã¸ã§ã¯ããæ¨æºã®ã¢ããªã±ã¼ã·ã§ã³ããã¸ã§ã¯ãã¨ãã¦ä½æ
ããã±ã¼ã¸åã¯ã©ã¤ãã©ãªã¨åä¸ã«ãã
[ã©ã¤ãã©ãªã®ããã±ã¼ã¸].testã¨ããããªãããå¥åã«ããã¨ã¯ã¾ãã®ã§æ³¨æ
Manifestã«instrumentationã¨uses-library追å
android:targetPackageã®å¤ã¯ã©ã¤ãã©ãªããã¸ã§ã¯ãã®ããã±ã¼ã¸=ãã¹ãããã¸ã§ã¯ãã®ããã±ã¼ã¸ã¨ãªã
TestCaseä½æ
æ®éã«ãã¹ãã±ã¼ã¹ãä½æãã
package com.example.lib; import junit.framework.TestCase; public class UtilTest extends TestCase { public void testEcho() { String send = "Hello"; String res = Util.echo(send); assertEquals(res, send); } }