この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
android:junit [2019/12/03 01:33] ips [対策2.PowerMockを使う] |
android:junit [2019/12/04 01:26] (現在) ips [Hamkrest - Hamcrest for Kotlin] |
||
---|---|---|---|
ライン 6: | ライン 6: | ||
[[https://github.com/npryce/hamkrest/blob/master/README.md|Hamkrest - Hamcrest for Kotlin]] | [[https://github.com/npryce/hamkrest/blob/master/README.md|Hamkrest - Hamcrest for Kotlin]] | ||
+ | com.natpryce.hamkrest → kotlin用のhamkrest | ||
+ | org.hamcrest. → 普通のhamkrest | ||
[[https://qiita.com/opengl-8080/items/e57dab6e1fa5940850a3|HamcrestのMatchersに定義されているメソッドの使い方メモ]] | [[https://qiita.com/opengl-8080/items/e57dab6e1fa5940850a3|HamcrestのMatchersに定義されているメソッドの使い方メモ]] | ||
+ | |||
+ | [[https://github.com/npryce/hamkrest/blob/master/docs/function-references.md|Shortcuts: using function references as Matchers]] | ||
<code kotlin build.gradle(module)> | <code kotlin build.gradle(module)> | ||
ライン 20: | ライン 24: | ||
<code kotlin> | <code kotlin> | ||
- | import com.natpryce.hamkrest.* | + | import com.natpryce.hamkrest.* // kotlin用のhamkrest |
import com.natpryce.hamkrest.assertion.assertThat | import com.natpryce.hamkrest.assertion.assertThat | ||
import org.junit.Test | import org.junit.Test | ||
ライン 32: | ライン 36: | ||
assertThat("Hello", equalTo("Hello")) //文字列一致 | assertThat("Hello", equalTo("Hello")) //文字列一致 | ||
assertThat( Integer.parseInt(actual.ans),allOf(greaterThanOrEqualTo(1), lessThanOrEqualTo(9))) //1~9まで | assertThat( Integer.parseInt(actual.ans),allOf(greaterThanOrEqualTo(1), lessThanOrEqualTo(9))) //1~9まで | ||
+ | |||
+ | // listsは1..9まですべてを含む | ||
+ | val contain = Matcher(List<out Int>::containsAll,listOf(1,2,3,4,5,6,7,8,9)) | ||
+ | assertThat(lists,contain ) | ||
} | } | ||