0

I have 2 adjacent classes for my integration tests with the following signatures:

@ActiveProfiles("test")
public class AuthenticationTransformationTest extends AbstractKafkaIntegrationTest {
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(classes = {KafkaIntegrationConfig.class})
@RunWith(SpringRunner.class)
public abstract class AbstractKafkaIntegrationTest {

The idea is -- within this repo, we have N modules that utilize Spring. I'm looking to have a util module that contains the Abstract class so others within their own modules can extend from it and run their tests. When moving the abstract class to another module, I have a bunch of errors getting the annotations to resolve, despite adding the required dependencies, etc.

What is the best, recommended way to have a util module that only provides the testing utility class? Do I need to throw an @Configuration annotation somewhere for this to be picked up correctly?

Edit: I've moved the classes to test dir - it helped resolve the annotation issue, but the dependency on the test util isn't resolving via Gradle:

.
├── moduleA
│   └── test
│       └── java
│           └── com
│               └── thing
│                   └── integration
│                       └── my-test.java
└── moduleB
    └── test
        └── java
            └── com
                └── thing
                    └── test-util.java

preamble of moduleA

plugins {
    id "org.springframework.boot" version "$springBootVersion"
    id "com.google.cloud.tools.jib" version "$jibVersion"
    id "application"
    id "java"
}

group "com.thing.test"
sourceCompatibility = JavaVersion.VERSION_11

dependencies {
    testImplementation(testFixtures(project(':moduleB')))

I've tried just:

    testImplementation(project(':moduleB')) 

and get the same issue

Ryan
  • 1,102
  • 1
  • 15
  • 30
  • so why not extract this into a separate test module then? Or am I missing something? – Eugene Mar 21 '21 at 19:14
  • if I have moduleA with testX and moduleB with testUtility, do you know how I can properly add the dependency? I'm using gradle I can't get it to resolve. – Ryan Mar 21 '21 at 19:18
  • it is a bit hard to tell without knowing more details, but inner dependencies can be specified like this, for example: `project(':rest') { dependencies { implementation project(':services-api') implementation project(':services-impl') implementation project(':models') } }` (literally taken from our code base) – Eugene Mar 21 '21 at 19:20
  • let me update the original post with directory structure and example – Ryan Mar 21 '21 at 19:21
  • updated the OP to contain example – Ryan Mar 21 '21 at 19:24
  • You need to tell gradle that `moduleA` depends on `moduleB` via `testImplementation`, like I've shown you in the example above, that should work. – Eugene Mar 21 '21 at 19:27
  • is that not what I've done? – Ryan Mar 21 '21 at 19:28
  • what if you change it to `project(':moduleA') { dependencies { testImplementation project(':moduleB') } }`? – Eugene Mar 21 '21 at 19:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230195/discussion-between-john-and-eugene). – Ryan Mar 21 '21 at 19:32
  • I am glad you got it resolved, in the meanwhile I really think this is a duplicate as stated in the chat we had. – Eugene Mar 21 '21 at 20:05

0 Answers0