<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>FEST Android by Square, Inc.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A set of FEST 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>FEST Android</h1>
            <h3>A set of FEST assertions geared toward testing Android.</h3>
            <ul class="unstyled">
                <li><a href="https://oss.sonatype.org/content/repositories/releases/com/squareup/fest-android/1.0.1/fest-android-1.0.1.jar" class="btn btn-large btn-inverse" id="download">Download v1.0.1</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 FEST provide a great starting point for writing tests.</p>
        <p>This library is an extension of <a href="http://fest.easytesting.org/">FEST</a> which aims to make it even easier to test Android.</p>
      </div>
    </div>
    <div class="row examples section">
      <div class="span8 offset2">
        <h5>FEST 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 FEST</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>FEST Android</em> assertion produces an output which allows you to immediately recognize the problem: <code>Expected visibility &lt;gone> but was &lt;invisible>.</code></p>
        <p>Compare that to the output of regular <em>FEST</em> <code>expected:&lt;[8]> but was:&lt;[4]></code> and regular <em>JUnit</em> <code>expected: &lt;8> but was: &lt;4></code> and you should immediately see the advantage.</p>
        <p>Because <em>FEST 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>FEST 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 FEST</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.fest.assertions.api.ANDROID.assertThat;</pre>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <h5>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&lt;CustomLayoutAssert, CustomLayout> {
  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>To include this new assertion, create your own class which extends from <code>ANDROID</code>.</p>
        <pre class="prettyprint">public class MyAssertions extends ANDROID {
  public static CustomLayoutAssert assertThat(CustomLayout actual) {
    return new CustomLayoutAssert(actual);
  }
}</pre>
        <p>For more information about writing custom assertions see the <a href="https://github.com/alexruiz/fest-assert-2.x/wiki/Creating-specific-assertions">official documentation</a>.</p>
      </div>
    </div>
    <div class="row section">
      <div class="span10 offset1">
        <h5>Download</h5>
        <p>Download <a href="https://oss.sonatype.org/content/repositories/releases/com/squareup/fest-android/1.0.0/fest-android-1.0.0.jar">the latest jar</a> or grab via Maven:</p>
        <pre class="prettyprint">&lt;dependency>
  &lt;groupId>com.squareup&lt;/groupId>
  &lt;artifactId>fest-android&lt;/artifactId>
  &lt;version>1.0.1&lt;/version>
&lt;/dependency></pre>
        <p><em>Compilation requires Android 4.1 or newer.</em></p>
      </div>
    </div>
    <div class="span12 foot">
        <a id="ribbon" href="https://github.com/square/fest-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> prettyPrint(); </script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</body>
</html>
