{"id":3594,"url":"https://github.com/square/assertj-android","last_synced_at":"2025-12-30T08:27:42.351Z","repository":{"id":6433417,"uuid":"7672099","full_name":"square/assertj-android","owner":"square","description":"A set of AssertJ helpers geared toward testing Android.","archived":true,"fork":false,"pushed_at":"2018-03-05T20:29:14.000Z","size":3225,"stargazers_count":1578,"open_issues_count":10,"forks_count":167,"subscribers_count":73,"default_branch":"master","last_synced_at":"2024-04-13T17:52:11.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://square.github.io/assertj-android/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-17T18:51:30.000Z","updated_at":"2024-04-01T03:57:50.000Z","dependencies_parsed_at":"2022-09-09T09:30:59.408Z","dependency_job_id":null,"html_url":"https://github.com/square/assertj-android","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fassertj-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fassertj-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fassertj-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fassertj-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/assertj-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234555621,"owners_count":18851804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:45.891Z","updated_at":"2025-09-28T19:31:03.346Z","avatar_url":"https://github.com/square.png","language":"Java","funding_links":[],"categories":["Test","Libraries","Java","测试","Libs","Uncategorized","库"],"sub_categories":["Testing","\u003cA NAME=\"Test\"\u003e\u003c/A\u003eTest","Uncategorized","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#testing)测试"],"readme":"AssertJ Android\n===============\n\nA set of AssertJ assertions geared toward testing Android.\n\n## Deprecated\n\nThe support libraries and play services are developing at a rate which this library cannot sustain. Additionally, we no longer think AssertJ's model for supporting alternate assertions is a good practice.\n\nWe recommend using [Truth](https://github.com/google/truth) which has vastly superior extensibility model which, when coupled with things like Kotlin's `apply` method create a really nice assertion experience.\n\n---\n\nWriting tests is not the most glamorous part of developing an Android\napplication but it is an invaluable one. Using libraries like JUnit and AssertJ\nprovide a great starting point for writing tests.\n\nThis library is an extension of [AssertJ][1] which aims to make it even easier to test\nAndroid.\n\n\n\nExamples\n--------\n\n *  AssertJ Android:\n\n    ```java\n    assertThat(view).isGone();\n    ```\n\n *  Regular JUnit:\n\n    ```java\n    assertEquals(View.GONE, view.getVisibility());\n    ```\n\n *  Regular AssertJ:\n\n    ```java\n    assertThat(view.getVisibility()).isEqualTo(View.GONE);\n    ```\n\nWhen failing, the _AssertJ Android_ assertion produces an output which allows you\nto immediately recognize the problem:\n`Expected visibility \u003cgone\u003e but was \u003cinvisible\u003e`.\n\nCompare that to the output of regular _AssertJ_ `Expected:\u003c[8]\u003e but was:\u003c[4]\u003e` and\nregular _JUnit_ `Expected: \u003c8\u003e but was: \u003c4\u003e` and you should immediately see the\nadvantage.\n\n\nBecause _AssertJ Android_ offers assertions directly on objects rather than\nproperties they can be chained together.\n\n *  AssertJ Android:\n\n    ```java\n    assertThat(layout).isVisible()\n        .isVertical()\n        .hasChildCount(4)\n        .hasShowDividers(SHOW_DIVIDERS_MIDDLE);\n    ```\n\n *  Regular JUnit:\n\n    ```java\n    assertEquals(View.VISIBLE, layout.getVisibility());\n    assertEquals(VERTICAL, layout.getOrientation());\n    assertEquals(4, layout.getChildCount());\n    assertEquals(SHOW_DIVIDERS_MIDDLE, layout.getShowDividers());\n    ```\n\n *  Regular AssertJ:\n\n    ```java\n    assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);\n    assertThat(layout.getOrientation()).isEqualTo(VERTICAL);\n    assertThat(layout.getChildCount()).isEqualTo(4);\n    assertThat(layout.getShowDividers()).isEqualTo(SHOW_DIVIDERS_MIDDLE);\n    ```\n\nAssertions exist for nearly every object that you would ever want to test, from\n`LinearLayout` to `ActionBar` to `Fragment` to `MenuItem`. Everything in the\nsupport library is included too.\n\nTo get started writing tests add the following import:\n\n```java\nimport static org.assertj.android.api.Assertions.assertThat;\n```\n\n\n\nAdd-On Modules\n--------------\n\nModules are also provided for the add-on Android libraries. Add the dependency\n(listed below) and use the following imports:\n\n * support-v4: `import static org.assertj.android.support.v4.api.Assertions.assertThat;`\n * play-services: `import static org.assertj.android.playservices.api.Assertions.assertThat;`\n * appcompat-v7: `import static org.assertj.android.appcompat.v7.api.Assertions.assertThat;`\n * mediarouter-v7: `import static org.assertj.android.mediarouter.v7.api.Assertions.assertThat;`\n * gridlayout-v7: `import static org.assertj.android.gridlayout.v7.api.Assertions.assertThat;`\n * cardview-v7: `import static org.assertj.android.cardview.v7.api.Assertions.assertThat;`\n * recyclerview-v7: `import static org.assertj.android.recyclerview.v7.api.Assertions.assertThat;`\n * palette-v7: `import static org.assertj.android.palette.v7.api.Assertions.assertThat;`\n\n\n\nExtending\n---------\n\nThe provided assertions have also been designed to be extended for any custom\ncontrols you have developed.\n\n```java\npublic class CustomLayout extends LinearLayout {\n  public int getBehavior() {\n    /* ... */\n  }\n}\n```\n\nUse the following pattern to set up your assertions.\n\n```java\npublic class CustomLayoutAssert extends AbstractLinearLayoutAssert\u003cCustomLayoutAssert, CustomLayout\u003e {\n  public static CustomLayoutAssert assertThat(CustomLayout actual) {\n    return new CustomLayoutAssert(actual);\n  }\n\n  public CustomLayoutAssert(CustomLayout actual) {\n    super(actual, CustomLayoutAssert.class);\n  }\n\n  public CustomLayoutAssert hasSomeBehavior() {\n    isNotNull();\n    assertThat(actual.getBehavior())\n        .overridingErrorMessage(\"Expected some behavior but was doing other behavior.\")\n        .isEqualTo(42)\n    return this;\n  }\n}\n```\n\nNow static import `CustomLayoutAssert.assertThat` in your test classes.\n\nFor more information about writing custom assertions see the [official documentation][2].\n\n\n\nDownload\n--------\n\nAndroid module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android:1.2.0'\n```\n\nsupport-v4 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-support-v4:1.2.0'\n```\n\nGoogle Play Services module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-play-services:1.2.0'\n```\n\nappcompat-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-appcompat-v7:1.2.0'\n```\n\nDesign library module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-design:1.2.0'\n```\n\nmediarouter-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-mediarouter-v7:1.2.0'\n```\n\ngridlayout-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-gridlayout-v7:1.2.0'\n```\n\ncardview-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-cardview-v7:1.2.0'\n```\n\nrecyclerview-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-recyclerview-v7:1.2.0'\n```\n\npalette-v7 module:\n```groovy\nandroidTestCompile 'com.squareup.assertj:assertj-android-palette-v7:1.2.0'\n```\n\nSnapshots of the development version are available in [Sonatype's `snapshots` repository][snap].\n\n\n\nLicense\n-------\n\n    Copyright 2013 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n\n\n [1]: http://joel-costigliola.github.io/assertj/\n [2]: http://joel-costigliola.github.io/assertj/assertj-core-custom-assertions.html\n [snap]: https://oss.sonatype.org/content/repositories/snapshots/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fassertj-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fassertj-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fassertj-android/lists"}