Questions tagged [google-truth]

Google's assertion/proposition framework for testing.

Google Truth is a fluent assertion library for Java and Android tests (similar to AssertJ):

assertThat(notificationText).contains("testuser@google.com");
26 questions
27
votes
4 answers

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 with truth. There are no samples around…
Imanol
  • 4,824
  • 2
  • 28
  • 35
15
votes
5 answers

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 procedure to add the library in my build.gradle…
ysoa
  • 153
  • 1
  • 5
12
votes
4 answers

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: Task :api:checkDebugAndroidTestDuplicateClasses…
tir38
  • 9,810
  • 10
  • 64
  • 107
11
votes
1 answer

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 examples I can not find any advantage of start…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
10
votes
1 answer

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 I write the @test methods and test suites the way…
Saurabh Patil
  • 4,170
  • 4
  • 32
  • 33
8
votes
3 answers

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 { ... testImplementation 'junit:junit:4.12' …
4
votes
1 answer

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.truth.Truth.assertAbout; import static…
sockeqwe
  • 15,574
  • 24
  • 88
  • 144
3
votes
2 answers

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 : a huge document that…
apflieger
  • 912
  • 10
  • 18
3
votes
4 answers

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 tested obj does contain exactly one object of instance…
rds
  • 26,253
  • 19
  • 107
  • 134
2
votes
1 answer

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' androidTestImplementation…
Enselic
  • 4,434
  • 2
  • 30
  • 42
2
votes
1 answer

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 plugins { id 'java-library' id…
John Mercier
  • 1,637
  • 3
  • 20
  • 44
2
votes
1 answer

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 envisioning something…
dimo414
  • 47,227
  • 18
  • 148
  • 244
1
vote
4 answers

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"); assertThat(strToCheck).endsWith("@"); In another word, I am…
Chen
  • 860
  • 10
  • 32
1
vote
1 answer

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 import static…
Nick
  • 220
  • 1
  • 2
  • 12
1
vote
1 answer

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: Int = 0, var name: String )…
Louis
  • 364
  • 3
  • 11
1
2