Accessing test resources from another project

Currently, I have some awkward gradle configuration for what I suspect should be implicit… If it’s possible to do this implicitly, please advise. Otherwise I’ll ask my question and assume this needs more configuration…

I have project B that depends upon project A. In project A, it defines some classes and Spring config files under /src/test/java and /src/test/resources accordingly. The unit tests in project A work OK.

Now, I’m writing tests in project B that need to use the test classes and resources from project A. In project A’s build.gradle file I have:

configurations {
  testFixtures {
   extendsFrom testCompile
 }
}

and in project B, I have:

dependencies {
    ...
    testCompile project(path: ':ProjectA', configuration: 'testFixtures')
    ...
}

This allows my tests in project B to reference the test classes from project A, but not the spring config files that were located under /src/test/resources

How can I make these available to project B?

Thanks,

Alex

Hey,

Try extending testRuntime instead of testCompile.

Also, you can always declare any files directly in a configuration:

dependencies {
  testFixtures someFileCollection
}

Hope that helps!

I tried extending testRuntime instead but it still doesn’t include the test resources.

How would I reference the test resources as a file collection?

Gradle syntax is so obscure and unintuitive there’s not way to know, unless you already know.

Here’re examples of attaching files to the configuration:

dependencies {
  //this might be what you need:
  someConf sourceSets.resources
    //other examples:
  someConf files("file1.jar", "file2.jar")
  someConf fileTree("someDir")
}

Hope that helps!