Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add assertion test framework best practice for Android using AssertJ-Android #129

Merged
merged 2 commits into from Dec 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@ Lessons learned from Android developers in [Futurice](http://www.futurice.com).
#### [Also keep dimens.xml DRY, define generic constants](#dimensxml)
#### [Do not make a deep hierarchy of ViewGroups](#deephierarchy)
#### [Avoid client-side processing for WebViews, and beware of leaks](#webviews)
#### [Use Robolectric for unit tests, Robotium for connected (UI) tests](#test-frameworks)
#### [Use Robolectric for unit tests, Robotium for connected (UI) tests, and AssertJ-Android for easier assertions in your Android tests](#test-frameworks)
#### [Use Genymotion as your emulator](#emulators)
#### [Always use ProGuard or DexGuard](#proguard-configuration)
#### [Use SharedPreferences for simple persistence, otherwise ContentProviders](#data-storage)
Expand Down Expand Up @@ -438,6 +438,19 @@ solo.clickOnText("Edit File Extensions");
Assert.assertTrue(solo.searchText("rtf"));
```

**[AssertJ-Android](http://square.github.io/assertj-android/) an AssertJ extension library making assertions easy in Android tests** which you can use in both your Robolectric or Robotium. Assert-J comes with plenty extra libraries that make it even easier for you to test Android specific components, such as the Android support, play services and appcomat libraries.
Test assertion will look as simple as:

```java
// Example assertion on an intent with AssertJ-Android
Intent nextStartedServiceIntent = shadowOf(activity).getNextStartedService();
assertThat(nextStartedServiceIntent)
.isNotNull()
.hasAction("org.example.action.YOUR_ACTION")
.hasExtra("yourExtra", "expectedValue")
... so on
```

### Emulators

If you are developing Android apps as a profession, buy a license for the [Genymotion emulator](http://www.genymotion.com/). Genymotion emulators run at a faster frames/sec rate than typical AVD emulators. They have tools for demoing your app, emulating network connection quality, GPS positions, etc. They are also ideal for connected tests. You have access to many (not all) different devices, so the cost of a Genymotion license is actually much cheaper than buying multiple real devices.
Expand Down