This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathindex.html
170 lines (166 loc) · 9.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AssertJ Android by Square, Inc.</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A set of AssertJ assertions geared toward testing Android." />
<link href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" rel="stylesheet" title="roboto">
<link href="static/bootstrap.min.css" rel="stylesheet">
<link href="static/bootstrap-responsive.min.css" rel="stylesheet">
<link href="static/prettify.css" rel="stylesheet">
<link href="static/app.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="span8 offset2 lead">
<h1>AssertJ Android</h1>
<h3>A set of AssertJ assertions geared toward testing Android.</h3>
<ul class="unstyled">
<li><a href="#download" class="btn btn-inverse btn-large">Download</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="span10 offset1">
<p>Writing tests is not the most glamorous part of developing an Android application but it is an invaluable one. Using libraries like JUnit and AssertJ provide a great starting point for writing tests.</p>
<p>This library is an extension of <a href="http://joel-costigliola.github.io/assertj/">AssertJ</a> which aims to make it even easier to test Android.</p>
</div>
</div>
<div class="row examples section">
<div class="span8 offset2">
<h5>AssertJ Android</h5>
<pre class="prettyprint">assertThat(view).isGone();</pre>
</div>
</div>
<div class="row">
<div class="span6 bad">
<h5>Regular JUnit</h5>
<pre class="prettyprint">assertEquals(View.GONE, view.getVisibility());</pre>
</div>
<div class="span6 bad">
<h5>Regular AssertJ</h5>
<pre class="prettyprint">assertThat(view.getVisibility()).isEqualTo(View.GONE);</pre>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<p>When failing, the <em>AssertJ Android</em> assertion produces an output which allows you to immediately recognize the problem: <code>Expected visibility <gone> but was <invisible>.</code></p>
<p>Compare that to the output of regular <em>AssertJ</em> <code>expected:<[8]> but was:<[4]></code> and regular <em>JUnit</em> <code>expected: <8> but was: <4></code> and you should immediately see the advantage.</p>
<p>Because <em>AssertJ Android</em> offers assertions directly on objects rather than properties they can be chained together.</p>
</div>
</div>
<div class="row examples section">
<div class="span8 offset2">
<h5>AssertJ Android</h5>
<pre class="prettyprint">assertThat(layout).isVisible()
.isVertical()
.hasChildCount(4)
.hasShowDividers(SHOW_DIVIDERS_MIDDLE);</pre>
</div>
</div>
<div class="row">
<div class="span6 bad">
<h5>Regular JUnit</h5>
<pre class="prettyprint">assertEquals(View.VISIBLE, layout.getVisibility());
assertEquals(VERTICAL, layout.getOrientation());
assertEquals(4, layout.getChildCount());
assertEquals(SHOW_DIVIDERS_MIDDLE, layout.getShowDividers());</pre>
</div>
<div class="span6 bad">
<h5>Regular AssertJ</h5>
<pre class="prettyprint">assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(layout.getOrientation()).isEqualTo(VERTICAL);
assertThat(layout.getChildCount()).isEqualTo(4);
assertThat(layout.getShowDividers()).isEqualTo(SHOW_DIVIDERS_MIDDLE);</pre>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<p>Assertions exist for nearly every object that you would ever want to test, from <code>LinearLayout</code> to <code>ActionBar</code> to <code>Fragment</code> to <code>MenuItem</code>. Everything in the support library is included too.</p>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<p>To get started writing tests add the following import:</p>
<pre class="prettyprint">import static org.assertj.android.api.Assertions.assertThat;</pre>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<h5 id="add-ons">Add-On Modules</h5>
<p>Modules are also provided for the add-on Android libraries. Add the dependency (listed below) and use the following imports:</p>
<ul>
<li><p>support-v4</p><pre class="prettyprint">import static org.assertj.android.support.v4.api.Assertions.assertThat;</pre></li>
<li><p>Google Play Services</p><pre class="prettyprint">import static org.assertj.android.playservices.api.Assertions.assertThat;</pre></li>
<li><p>appcompat-v7</p><pre class="prettyprint">import static org.assertj.android.appcompat.v7.api.Assertions.assertThat;</pre></li>
<li><p>mediarouter-v7</p><pre class="prettyprint">import static org.assertj.android.mediarouter.v7.api.Assertions.assertThat;</pre></li>
<li><p>gridlayout-v7</p><pre class="prettyprint">import static org.assertj.android.gridlayout.v7.api.Assertions.assertThat;</pre></li>
<li><p>cardview-v7</p><pre class="prettyprint">import static org.assertj.android.cardview.v7.api.Assertions.assertThat;</pre></li>
<li><p>recyclerview-v7</p><pre class="prettyprint">import static org.assertj.android.recyclerview.v4.api.Assertions.assertThat;</pre></li>
<li><p>pallete-v7</p><pre class="prettyprint">import static org.assertj.android.pallete.v4.api.Assertions.assertThat;</pre></li>
</dl>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<h5 id="extending">Extending</h5>
<p>The provided assertions have also been designed to be extended for any custom controls you have developed.</p>
<pre class="prettyprint">public class CustomLayout extends LinearLayout {
public int getBehavior() {
/* ... */
}
}</pre>
<p>Use the following pattern to set up your assertions.</p>
<pre class="prettyprint">public class CustomLayoutAssert extends AbstractLinearLayoutAssert<CustomLayoutAssert, CustomLayout> {
public static CustomLayoutAssert assertThat(CustomLayout actual) {
return new CustomLayoutAssert(actual);
}
public CustomLayoutAssert(CustomLayout actual) {
super(actual, CustomLayoutAssert.class);
}
public CustomLayoutAssert hasSomeBehavior() {
isNotNull();
assertThat(actual.getBehavior())
.overridingErrorMessage("Expected some behavior but was doing other behavior.")
.isEqualTo(42)
return this;
}
}</pre>
<p>Now static import <code>CustomLayoutAssert.assertThat</code> in your test classes.</p>
<p>For more information about writing custom assertions see the <a href="http://joel-costigliola.github.io/assertj/assertj-core-custom-assertions.html">official documentation</a>.</p>
</div>
</div>
<div class="row section">
<div class="span10 offset1">
<h5 id="download">Download</h5>
<ul>
<li><p>Android module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>support-v4 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-support-v4:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>Google Play Services module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-play-services:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>appcompat-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-appcompat-v7:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>mediarouter-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-mediarouter-v7:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>gridlayout-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-gridlayout-v7:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>cardview-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-cardview-v7:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>recyclerview-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-recyclerview-v7:<span class="maven-version">1.0.0</span>'</pre></li>
<li><p>pallete-v7 module:</p><pre class="prettyprint">androidTestCompile 'com.squareup.assertj:assertj-android-pallete-v7:<span class="maven-version">1.0.0</span>'</pre></li>
</ul>
</div>
</div>
<div class="span12 foot">
<a id="ribbon" href="https://github.com/square/assertj-android"><img src="static/ribbon.png" alt="Fork me on GitHub"></a>
<p><a href="http://squareup.com"><img src="static/square.png" alt="by Square, Inc."></a></p>
</div>
</div>
<script src="static/prettify.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="static/jquery-maven-artifact.min.js"></script>
<script>
prettyPrint();
$.fn.artifactVersion('com.squareup.assertj', 'assertj-android', function(version, url) {
$('.maven-version').text(version);
});
</script>
</body>
</html>