第一次寫(翻譯)這麼長的文章,請多包含. 本標題純粹是別人的廣告語,它說他能夠android
日誌git
import de.akquinet.android.androlog.Log; import android.app.Activity; import android.os.Bundle; public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initializes androlog // This will read /sdcard/my.application.properties Log.init(this); // Log a message Log.i(this, "This is a logged message"); setContentView(R.layout.main); } }
快速測試github
public void testValidAuth() throws Exception { activity().view().withId(R.id.username).setText("testuser"); activity().view().withId(R.id.password).setText("testpw"); activity().view().withId(R.id.buttonSubmit).click(); NextActivity nextActivity = await().activity( NextActivity.class, 10, TimeUnit.SECONDS); assertThat(nextActivity, notNullValue()); assertThat(activity(nextActivity).view(). withId(R.id.nextActivityContent), hasText("success")); }
持續集成和測試你的應用後端
讓你的應用能夠直接上架(With ProGuard to AppStore)安全
得到應用的錯誤等日誌反饋app
構建企業應用程序maven
企業應用程序有不一樣的要求,與後端系統的有關部署,安全和通訊。它爲在Android上構建企業解決方案提供了幾個組件:ide
交貨門戶網站:管理用戶和交付/更新/管理您的應用程序在空中。工具
先進的後端鏈接:易於與您的後端使用REST,Web服務,JSON或protobuf的溝通。支持幾種加密方法,以及使用雲服務。 從現場設備的數據同步:保持與後端同步,支持離線模式,合併。單元測試
隱私權存儲:提升你的設備上的數據經過加密和您的應用程序的私有數據的安全性。
使用STAND,你能夠輕鬆地構建基於Android的企業級解決方案。
MAVEN PLUGIN
網址: http://code.google.com/p/maven-android-plugin
源代碼: GitHub
MAVEN 骨架
使用方法:
mvn archetype:generate \ -DarchetypeArtifactId=android-quickstart \ -DarchetypeGroupId=de.akquinet.android.archetypes \ -DarchetypeVersion=1.0.11 \ -DgroupId=your.company \ -DartifactId=my-android-application
源代碼:Github
ANDROLOG
Maven依賴
<dependency> <groupId>de.akquinet.android.androlog</groupId> <artifactId>androlog</artifactId> <version>1.0.1</version> <scope>compile</scope> </dependency>
使用方法1(跟Android log同樣使用,無需配置):
import de.akquinet.android.androlog.Log; public class AndrologExample { public static final String TAG = "MY_TAG"; public void doSomething() { Log.i(TAG, "A message"); } }
使用方法2:
import de.akquinet.android.androlog.Log; import android.app.Activity; import android.os.Bundle; public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initializes androlog // This will read the /sdcard/my.application.properties file Log.init(this); // Log a messgage Log.i(this, "This is a logged message"); setContentView(R.layout.main); } }
配置:
文件名是包名+.properties.是否是很簡單?
格式以下:
androlog.active = true|false androlog.default.level=VERBOSE|DEBUG|INFO|WARN|ERROR 默認Info org.package.name = info //這個格式很眼熟吧? androlog.delegate.wtf = false //若是你的系統低於2.3則須要這樣設置以避免報錯
發佈前提條件,在~/.m2/settings.xml定義
<profiles> <profile> <id>android</id> <properties> <!-- CHANGE HERE --> <sdk.path>/Users/clement/dev/android</sdk.path> </properties> </profile> <!-- others profiles --> </profiles> <activeProfiles> <activeProfile>android</activeProfile> </activeProfiles>
源代碼:Github
更好的單元測試工具 - MARVIN
Maven依賴:
<dependency> <groupId>de.akquinet.android.marvin</groupId> <artifactId>marvin</artifactId> <version>1.1.0</version> <<scope>compile</scope> </dependency>
原生的測試方法:
public class LoginActivityTest extends AndroidTestCase { public void testLogin() { Instrumentation instrumentation = getInstrumentation(); ActivityMonitor monitor = instrumentation .addMonitor(MainActivity.class.getName(), null, false); Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClassName(instrumentation.getTargetContext(), LoginActivity.class.getName()); final LoginActivity loginActivity= (LoginActivity) instrumentation.startActivitySync(intent); instrumentation.waitForIdleSync(); injectViewTestActivity.runOnUiThread(new Runnable() { public void run() { EditText username = loginActivity .findViewById(R.id.username); EditText password = loginActivity .findViewById(R.id.password); username.setText("Username"); // Step 1 password.setText("Password"); // Step 2 loginActivity.findViewById(R.id.loginbutton) .performClick(); // Step 3 } }); Activity mainActivity = instrumentation .waitForMonitorWithTimeout(monitor, 30000); // Step 4 assertNotNull(mainActivity); // Step 5 } }
更好的測試方法(譯者:你認爲呢?):
public class LoginActivityTest extends ActivityTestCase<> { public LoginActivityTest(Class activityType) { super(LoginActivity.class); } public void testLogin() { // Step 1 activity().view().withId(R.id.username).setText("Username"); // Step 2 activity().view().withId(R.id.password).setText("Password"); // Step 3 activity().view().withId(R.id.loginbutton).click(); // Step 4 Activity mainActivity = await().activity(MainActivity.class, 30, TimeUnit.SECONDS); assertNotNull(mainActivity); //Step 5 } }
總結:
使用Marvin,你的測試能夠繼承如下幾個的類:AndroidTestCase, AndroidActivityTestCase, AndroidServiceTestCase.提供如下perform(), await() 和 activity() 或者 view()的交互方法.還支持HAMCREST Matcher, 還有幾個全局監控類:
getMostRecentlyStartedActivity() - 返回最後的已經開啓的 activitygetStartedActivities() - 返回全部當前正在運行的activity waitForActivity(Class, long, TimeUnit) - 延時啓動特定activity
源代碼:Github
簡化開發難度(代碼工人的福音)
簡單介紹: 使用roboject必須繼承RobojectActivity,包括幾個可用的註解
@InjectLayout: Injects an XML layout to your activity.
@InjectView: Inject an XML view to a field of your activity.
@InjectExtra: Inject an Intent extra passed from another activity to a field of your activity.
@InjectService: Inject the binder object of a service to a field of your activity.
源代碼:Github
All STAND frameworks are available under the Apache License 2.0
##真的是最後 本文來自英文網站