How can I run a unittest that depend a third party jar ?

42 views
Skip to first unread message

Victor Choy

unread,
Jun 18, 2021, 10:19:06 AM6/18/21
to lint-dev
lint().files(
TestFiles.java(
"""
package test.pkg;
import com.google.zxing.qrcode.QRCodeWriter;
public class TestClass {
public void aa() {
new QRCodeWriter();
}
}
"""
).indented()
""".trimIndent()
)
)
.issues(QRCodeDetector.ISSUE)
.run()
.expectClean()


QRCodeWriter is not android class. I find it does not work.
The  unit test of  class in android such as new Thread work well.  Why ? 
Thanks

dom...@azimo.com

unread,
Jun 18, 2021, 11:47:14 AM6/18/21
to lint-dev
I've encountered similar problem and would love to learn whether we can include external jars into unit runtime. 

I understand it might not meet your needs, but I managed to workaround this by including a shadow class that provided all the necessary methods, like so: 

```
@Language("JAVA")
String provides = "package dagger; public @interface Provides {}";
```

Tor Norbye

unread,
Jul 14, 2021, 8:07:07 PM7/14/21
to lint-dev
That's correct and that is in fact the recommended approach:

(You *can* link to actual jar files you've checked in as well (that's what the LibraryReferenceTestFile testfile is for) but there's usually no good reason to do this.)

-- Tor

Reply all
Reply to author
Forward
0 new messages