robfletcher
04/22/2020, 8:11 PMtask
methodcristiangm
04/24/2020, 8:51 AMchristophsturm
05/11/2020, 4:19 PMexpectCatching { … }.isA<BlahException>
should rethrow the exception if its not the expected exception, or at least show the stacktrace of the unexpected exceptionrobfletcher
07/15/2020, 8:00 PMsloydev
11/26/2020, 10:41 AMexpectThat(output) {
should("Replace anonymous id") {
get { anonymousId() }.isEqualTo("anonymous_user")
get { context().traits().anonymousId() }.isEqualTo("anonymous_user")
}
should("Remove advertisingId and deviceId") {
get { advertisingId() }.isNull()
get { deviceId() }.isNull()
}
}
So I get error messages like these:
✗ Replace anonymous id
▼ "5c6b6c02-4dd2d":
✗ is equal to "anonymous_user"
found "5c6b6c02-4dd2d"
▼ "5c6b6c02-4dd2d":
✗ is equal to "anonymous_user"
found "5c6b6c02-4dd2d"
✗ Remove advertisingId and deviceId
▼ "32c85c4d-c39b897c":
✗ is null
▼ "c55911907ad":
✗ is null
Roukanken
11/30/2020, 4:47 PMrocketraman
11/30/2020, 7:20 PMexactly
, atMost
, and atLeast
, but all of these take an additional predicate. Is the preferred approach to do this?
expectThat(it).get { count() }.isEqualTo(3)
Is there any particular reason that there isn't a count matcher directly on list?alorma
12/02/2020, 3:54 PMIntent
for android:
inline fun <reified T : Parcelable> Assertion.Builder<Intent>.hasParams(
paramsName: String,
noinline block: Assertion.Builder<T>.() -> Unit = {},
): Assertion.Builder<Intent> {
return assert("has params %s", expected = paramsName) {
val params = it.extras?.getParcelable<T>(paramsName)
if (params != null) {
expectThat(params).isA<T>().and(block)
} else {
fail()
}
}
}
When I use this extension, whatever check I put on following lines are marked ass successfull, but those should fail:
@Test
fun testHasParamsSuccess() {
val intent = Intent(getApplicationContext(), SelectCountryActivity::class.java)
.putExtra("param1", TestClass(id = "ABCD"))
expectThat(intent)
.hasParams<TestClass>("param1") { get { id }.isEqualTo("ABCD") }
.assertThat("Simple") { false } // Here assertThat { false } must fail
}
What I'm doing wrong with the hasParams
extension?rocketraman
01/19/2021, 3:11 PMList<Int>
and I want to check that the first value from the list is less than the second. How can I express this in Strikt?
expectThat(listOf(5, 6)) {
// this[1] is a builder, so can't do this:
this[0].isLessThan(this[1])
}
Note because of the way the unit test is structured, I don't actually have access to the original list, only the assertion builder. So I can't just do this[0].isLessThan(originalList[1])
.christophsturm
02/01/2021, 12:17 PMimport strikt.api.expectThat
import strikt.assertions.containsExactly
data class Person(val name: String, val age: Int)
expectThat(listOf(Person("james", 28), Person("jimmy", 28))).containsExactly(
Person("james", 28), Person("jimmy", 28)
)
but what if there is a third field that is random, and that i can’t assert on, what would be the best way to write that in strikt?
data class Person(val name: String, val age: Int, val weight:Double=Random.nextDouble())
i want all the elements and the order but not assert on weight.robfletcher
02/03/2021, 5:26 PMrobfletcher
02/08/2021, 7:11 PMstrikt-java-time
in favor of a more general strikt-jvm
. Some of the JVM-specific stuff from strikt-core
also moves to the new module.alorma
02/24/2021, 2:42 PMcom.infojobs.app.base.datasource.cachedb.DateConverterTest > should convert Instant objects FAILED
org.opentest4j.AssertionFailedError: ▼ Expect that 2021-02-24T14:04:22.023Z:
✗ is equal to 2021-02-24T14:04:22.023564Z
found 2021-02-24T14:04:22.023Z
Wouldn't be better to show like this:
com.infojobs.app.base.datasource.cachedb.DateConverterTest > should convert Instant objects FAILED
org.opentest4j.AssertionFailedError:
▼ Expect that 2021-02-24T14:04:22.023Z:
✗ is equal to 2021-02-24T14:04:22.023564Z
found 2021-02-24T14:04:22.023Z
????rocketraman
03/10/2021, 1:50 PMIterable<T>
and returns a subset of that given a single element T
. For example, assume my function has signature fun <T> Iterable<T>.priorAdjacent(elem: T): List<T>
.
Currently use the pattern: expectThat(elems) { get { priorAdjacent(elems[3]) } isEqualTo elems.slice(1..2) }
which reads nicely and produces understandable failure messages. That being said, is that the best approach?christophsturm
03/15/2021, 11:00 AMchristophsturm
03/25/2021, 11:10 PMSimonT
03/28/2021, 7:01 PMchristophsturm
04/07/2021, 10:24 PMchristophsturm
04/08/2021, 3:39 PMchristophsturm
04/16/2021, 10:57 AMval parsed=expectThat("""{"abc":"def"}""").isValidJsonFor<MyType>()
dave08
04/26/2021, 11:20 AMand { get(SomeClass::someProp).isEqualTo(...) }
on a nullable type without isNotNull()
allows the and
, but has get()
undefined... I wonder if it makes sense to have an and
in this case in the first place...? What can one do with a nullable type?
Also, is there anything like a isNotNullAnd { ... }
or withNotNull { }
? I find myself doing expectThat(result).isNotNull().and { ... }
quite often...dave08
04/29/2021, 10:13 AMResult
assertions don't all work anymore... they complain that Result<T>
can't be cast to T
... maybe the fact that my T
is nullable is the cause?dave08
05/02/2021, 2:08 PMfun <V, E> Assertion.Builder<Result<V, E>>.isFailure(): Assertion.Builder<E> =
assert("is failure") {
when {
it is Err -> pass(
description = "threw %s",
actual = it.error
)
else -> fail(
description = "returned %s",
actual = it.get()
)
}
}
.get("exception") {
unwrapError()
}
fun <V, E> Assertion.Builder<Result<V, E>>.isSuccess(): Assertion.Builder<V> =
assert("is success") {
when {
it is Ok -> pass()
else -> fail(
description = "was error ${it.unwrapError()}",
)
}
}
.get("value") {
unwrap()
}
inline fun <reified E> Assertion.Builder<Result<Any?, E>>.failedWith() =
isFailure().isA<E>()
But when I try `
expectThat(result).isFailure().isA<SomeDomainError>()
I get:
org.opentest4j.AssertionFailedError: ▼ Expect that Ok(SomeStub(id=1,...)):
✗ is failure
returned SomeStub(id=1, ...)
dave08
05/02/2021, 3:15 PMinline fun <V, reified E> Assertion.Builder<Result<V, E>>.isFailureOf(): Assertion.Builder<E> =
assert("is failure of type ${E::class.simpleName}") {
when {
it is Err -> pass(
description = "threw %s",
actual = it.error
)
else -> fail(
description = "returned %s",
actual = it.get()
)
}
}
.get("exception") {
unwrapError()
}
But still won't give me the actual E
I want only the base class of it. Ideally I'd like to provide one type param, and have it report that name in the assert... but it seems like Kotlin won't let me use * for the V
in Result
...dave08
05/12/2021, 9:34 AMfirst { }
is a bit not fitting for Strikt's usually explicit and nice exceptions:
Mapping 'first matching element %s' failed with: Collection contains no element matching the predicate.
???robfletcher
05/23/2021, 3:27 PMAssertion.Builder<Result<*>>
) https://youtrack.jetbrains.com/issue/KT-46890christophsturm
08/25/2021, 7:54 AMrocketraman
08/25/2021, 4:36 PMfun <T: Comparable<T>> ClosedRange<T>.intersects(other: ClosedRange<T>): Boolean
.
My test has inputs (note there is a fake failure case here, 0..0
is not intersecting):
val intRangeRef = 1..5
val intRangesIntersecting = listOf(0..0, 0..2, 4..5, 4..6)
val intRangesDisjoint = listOf(-2..-1, 6..7)
How would you structure the assertions? So far I've got this, which produces nice output on failures, but thoughts on style?
expectThat(intRangesIntersecting).all {
get { intRangeRef.intersects(this) } isEqualTo true
get { this.intersects(intRangeRef) } isEqualTo true
}
expectThat(intRangesDisjoint).all {
get { intRangeRef.intersects(this) } isEqualTo false
get { this.intersects(intRangeRef) } isEqualTo false
}
christophsturm
09/08/2021, 9:25 AMGustavo Torrecilla
09/17/2021, 7:27 PMGustavo Torrecilla
09/17/2021, 7:27 PMrobfletcher
09/17/2021, 7:37 PM