Questions tagged [google-truth]
Google's assertion/proposition framework for testing.
26
questions
1
vote
4
answers
130
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
43
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 ...
0
votes
1
answer
640
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
662
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
514
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
392
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
733
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
799
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'
...
2
votes
1
answer
821
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
416
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
868
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 ...
7
votes
3
answers
2k
views
Android Studio - Unresolved reference: truth
I am trying to include the Google Truth framework in my project for testing. I followed the documentation on how to get the project setup.
This is from my app's build.gradle file:
dependencies {
...
12
votes
4
answers
5k
views
Android X + Truth + Guava test compile issue
I have an Android library (called api) gradle module as part of a larger project. I just migrated the whole project to AndroidX. I now have this error when running instrumentation test on the api lib:
...
1
vote
1
answer
757
views
How to compare two elements by using one of their attributes using Google Truth (Unit test)
I'm new to the Google Truth library and I was wondering if there was a way to compare two elements by using only one of their attributes. I know it is possible to do so with AssertJ so I was wondering ...
1
vote
1
answer
295
views
How to use custom comparator / diff in PAssert of PCollection
I have a code similar to the one below transforming a PCollections of Protocol Buffer messages. Because some of them are pretty big
I want to not only test it using for equality but also print where'...
15
votes
5
answers
8k
views
Android Studio : Cannot resolve symbol "Truth" (Truth library)
After coming across this gist : https://gist.github.com/chemouna/00b10369eb1d5b00401b, I noticed it was using the Google Truth library : https://google.github.io/truth/. So I started by following the ...
0
votes
1
answer
112
views
Use Truth to compare proto to string
Is there a way to use Google Truth to compare a protobuff to a string? I am hoping to find something that looks like this:
assertThat(myProto).isEqualToString("a: 1\n b:2")
1
vote
1
answer
275
views
Using Google Truth with Android text views
This may be obvious, but I can't seem to find a better way to handle this. I'm switching my project from using AssertJ to using Truth for several reasons that are beyond the scope of this question. In ...
9
votes
1
answer
2k
views
Testing frameworks: Is Google Truth a substitute for JUnit? How to I write test methods and test suites?
I came across Google Truth https://google.github.io/truth/ and thought to try it out. I read the information on that site but still have a basic question.
Is Truth a substitute for JUnit? How should ...
1
vote
1
answer
238
views
Expect (fail-at-end)
Can somebody show me a complete minimal example for fail at end behaviour?
The docs I found says just:
expect.that(actual).isEqualTo(expected); // supplied by @Rule
Use case: I would like to have ...
2
votes
1
answer
935
views
Making assertions about elements in an Iterable
I have a list of objects and I would like to make Truth-style assertions about the objects themselves, but I don't see any reasonable way to express anything more complex than equality assertions. I'm ...
26
votes
3
answers
15k
views
How to test that an expected exception is being thrown using google-truth?
I just want to test if an exception with a given message is being thrown using google-truth.
Is quite easy to do that using junit using @Test(expected=, but I'm unable to figure out how to do that ...
1
vote
1
answer
2k
views
How do I check that a Collection contains at least N matching elements in google-truth?
Is there a way to check that a collection contains at least n elements from a list of expected elements (e_1, e_2, ..., e_m) for m >= n? I'm thinking something similar to IterableSubject....
3
votes
4
answers
19k
views
How do I assert that a List contains exactly one instance of a particular class?
I'd like to test that a list contains instances of an object.
For instance, with a single instance:
assertThat(mylist).containsExactly(Matchers.any(ExpectedType.class));
The array returned from ...
4
votes
1
answer
494
views
Truth.assertAbout and JavaSourceSubjectFactory.javaSource()
I'm writing an annotation processor and want to write some unit tests for it by using google-compile-testing and truth:
So I want to write a very simple unit test.
import static com.google.common....
11
votes
1
answer
2k
views
Truth assertions library comparing to AssertJ
I used FEST-Assert and moved to AssertJ after it stopped development.
Recently I was pointed to Google repository with another assertions library Truth (http://google.github.io/truth/).
Reading the ...