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

Improve the explanation about custom assertions #255

Merged
merged 4 commits into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,35 +236,29 @@ assertProgressIsMax(R.id.seek_bar)

```

### Barista custom assert
### Custom assertions

Do your own asserts on given view, no more custom *Matcher*
If you have a special case not covered by the given assertions API, we encourage you to assert these special cases with our custom assertions API. It's a convenient way to replace plain `Matcher`s with complex assertions. With Barista, you can match any kind of view by knowing its type and passing its `viewId`, `text`, or a `Matcher<View>`. Once you matched it, you will be able to assert all its properties without adding any complex `Matcher` to your project.

```kotlin

assertAny<ViewType>(R.id.editText) {
it.text.toString() == "Hello!"
}

assertAny<ViewType>("Hello!") {
it.text.toString() == "Hello!"
}

assertAny<ViewType>(withId(R.id.editText)) {
it.text.toString() == "Hello!"
// Matching a Button by text
assertAny<Button>("Save") {
it.enabled == true
}

// With custom matcher description

assertAny<ViewType>(R.id.editText, "error message") {
it.text.toString() == "Hello!"
// Matching a RadioGroup by id
assertAny<RadioGroup>(R.id.radioGroup) {
it.checkedRadioButtonId == R.id.option1
}

assertAny<ViewType>("Hello!", "error message") {
it.text.toString() == "Hello!"
// Matching a Progressbar by a Matcher
assertAny<Progressbar>(withId(R.id.progressBar)) {
it.progress == 42
}

assertAny<ViewType>(withId(R.id.editText), "error message") {
// You can also define the assertion error message that will be shown if the assertion fails
assertAny<TextView>(R.id.textView, "text wasn't Hello!") {
it.text.toString() == "Hello!"
}
```
Expand Down