0

So here is the overview of my project: module A contains: - all boxstore data - boxstore mock for unit tests in module A

module B contains: - presenter that has BoxStore injected - presenterTest needs to mock BoxStore

Followed this link to mock BoxStore and it works fine when I wrote unit tests in module A. When it comes to creating the mock in module B I get NoClassDefFoundError which I understand since module B tests don't know about module A test objects.

So I did the following scenarios:

  1. Added in gradle of module B:

sourceSets { test.java.srcDirs += [etc...] }

So that module B would know about mock objects of module A.

  1. Duplicate mock of BoxStore in module B and use it in tests but BoxStore generates a java file under build folder and because of that I'm unable to create my mock since everything depends on MyObjectBox in order to generate a BoxStore.

Both methods failed :(

Any ideas on how I can unblock myself?

Karim Fikani
  • 356
  • 3
  • 23

1 Answers1

0

If you're using Gradle, take a look at the java-test-fixtures plugin that has been introduced in Gradle 5.6.2. It introduces a new testFixtures source set where you can place various test data for a specific module and new DSL that allows other modules to reference this data in their tests. In your case, I imagine you'd put the test data in module A's testFixtures directory, and reference it from module B:

// module A
dependencies {
  testImplementation(testFixtures(project(":module-B")))
}
Egor
  • 39,695
  • 10
  • 113
  • 130
  • I've upgraded to 5.6.2 and I got this error "ERROR: Unable to resolve dependency for ':module-A@debugUnitTest/compileClasspath': Could not resolve project :module-B" – Karim Fikani Oct 16 '19 at 18:13