Questions tagged [google-truth]
Google's assertion/proposition framework for testing.
google-truth
30
questions
1
vote
1
answer
45
views
How should I write Google-Truth Subjects for an object heirarchy that uses interfaces for multiple-inheritance?
The situation
I'm writing tests for a personal project (in Java17 using JUnit5/Jupiter and Google Truth ) where I use the multiple-inheritance of interfaces to define classes. For example:
Example
...
1
vote
1
answer
14
views
Why do I have to import Truth methods manually? (no auto suggestions even after Gradle sync)
Just installed Truth (actually the truth extensions) using
testImplementation(libs.androidx.truth)
where
[versions]
truthVersion = "1.6.0-beta01"
[libraries]
androidx-truth = { module = &...
0
votes
1
answer
53
views
Google Truth.assertThat.contains does not behave similar to List.contains
Using List.containsAll() and Truth.assertThat(list).contains(originalList) behaves differently.
Working as expected
assertThat(getItemsByChannelId.containsAll(entitiesChannelAPage2)).isTrue()
Not ...
-1
votes
1
answer
48
views
Google Truth not allowing us to do .isGreaterThanOrEqualTo() and cannot chain multiple calls
This is using Kotlin in android through tried in a non-android project. It just asks if we want to create the function. The value we wanted to compare was a Double, but .toInt() did not help.
FWIW, ...
1
vote
4
answers
276
views
Java Truth OR assertion
I would like to check with Java Truth assertion library if any of the following statements is satisfied:
assertThat(strToCheck).startsWith("a");
assertThat(strToCheck).contains("123&...
0
votes
1
answer
63
views
Possible to generate truth.dev Subjects for my domain model automaticly?
I'm a bit fan of Google's Truth.dev library. I have a large domain model in Java, and want to add several little custom assertions for them in my own Subject files. It's a bit of pain though to create ...
1
vote
1
answer
1k
views
Android Studio: Cannot import libraries JUnit and Truth
After creating class for unit tests like in official documentation I imported com.google.common.truth.Truth.assertThat and org.junit.Test libraries, but android studio can't pick it up and shows ...
0
votes
1
answer
1k
views
How to use assertThat with any condition?
How can I write the following assertion:
org.junit.Assert.assertTrue(result.any { it.name == "Foo" })
with Google Truth assertThat?
com.google.common.truth.Truth.assertThat(result...
1
vote
1
answer
823
views
Truth extensions causing rest of project to downgrade to guava android
If I add the com.google.truth.extensions:truth-proto-extension:1.1 jar to my bazel workspace, it seems to totally nuke the classes from com.google.guava:guava:28.2-jre, resulting in errors like
...
1
vote
1
answer
601
views
Truth ignore field
I am looking for Guava Truth equivalent of AssertJ usingElementComparatorIgnoringFields to ignore some field.
Exemple:
data class CalendarEntity(
@PrimaryKey(autoGenerate = true)
var id: ...
0
votes
1
answer
1k
views
How to check String equality in Google Truth assertions?
Truth.assertThat(actual).matches(expected) or Truth.assertThat(actual).isEqualTo(expected) ?
The docs say that the matches() method takes in a String in the form of a regex but not sure if a string ...
2
votes
1
answer
885
views
Unsatisfiable version constraints with androidTestImplementation Google Truth 1.0 and implementation Google Guava 27.0.1
In short
I can't get a minimal and new Android Studio project to build with the following added dependencies:
dependencies {
...
implementation 'com.google.guava:guava:27.0.1-android'
...
3
votes
1
answer
927
views
How to fix a split-package in test dependencies?
I have created an example project to explain the issue I am having. I have tests that use two dependency jars which have a split package. In this case google-truth has the split-package.
build.gradle
...
1
vote
1
answer
568
views
How to negate assertions with google truth
A list of Integers can be tested if it is ordered:
assertThat(list).isOrdered();
but how can it be tested that it is not ordered?
Is there a way to write:
assertThat(list).not().isOrdered();
Or ...
3
votes
2
answers
1k
views
How can I override default failure message of a test in google.Truth?
I am writing a test that assert that a document does not contain a specific String. When the test fails, it prints the 'actual' value in the form
expected not to contain a match for: my_regex
but was ...