Hi,
In IntelliJ my tests are showing errors due to an inability to see source code from my test fixtures. But everything seems to build correctly (using IntelliJ and Gradle) and my tests actually execute successfully…
So in IntelliJ I’m seeing red compilation errors:
The AbstractTest class is a “test fixture”. You can see it inside the “testFixtures” folder inside the directory structure on the left-hand side.
Maybe its an IntelliJ issue? Because using Gradle directly seems to work and I can even execute the test from within IntelliJ successfully…
I have two modules: “:shared:utils” and “:shared:aws-api”, and both modules have the same issue with test fixtures.
My root build.gradle:
plugins {
id “base”
id “idea”
// Gradle - Plugin: org.owasp.dependencycheck
// Using Gradle Plugins
// dependency-check – Usage
id “org.owasp.dependencycheck” version “6.5.1” apply false
}defaultTasks = [“build”]
subprojects {
// Gradle - Plugin: org.owasp.dependencycheck
// Using Gradle Plugins
apply plugin: “org.owasp.dependencycheck”// IDE configuration. // Download the source code of jar dependencies. // https://stackoverflow.com/questions/10156847/how-to-tell-gradle-to-download-all-the-source-jars idea { module { downloadSources = true } }
}
My settings.gradle:
rootProject.name = “automated_trading”
include “:shared:utils”
include “:shared:aws-api”
The build.gradle of my “:shared:utils” module
plugins {
id “idea”
id “java-library”
// Testing in Java & JVM projects
id “java-test-fixtures”// Plugin for better test output // https://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time // https://github.com/radarsh/gradle-test-logger-plugin id "com.adarshr.test-logger" version "3.1.0"
}
version = “1.0.0”
defaultTasks = [“build”]
sourceCompatibility = 1.16 // I tried 1.17, but something isn’t right with Gradle 7.3.3 - even though they say they support 1.17// ╔═══════════════════════════════════════════════════════════════════════════╗
// ║ Repositories ║
// ╚═══════════════════════════════════════════════════════════════════════════╝
repositories {
mavenCentral();maven { // for snakeyaml // https://central.sonatype.org/pages/ossrh-guide.html url "https://oss.sonatype.org/content/groups/public/"; }
}
// ╔═══════════════════════════════════════════════════════════════════════════╗
// ║ Dependencies ║
// ╚═══════════════════════════════════════════════════════════════════════════╝
dependencies {
// ╔═════════════════════╗
// ║ Module dependencies ║
// ╚═════════════════════╝// ╔════════════════════════════╗ // ║ Miscellaneous dependencies ║ // ╚════════════════════════════╝ // https://mvnrepository.com/artifact/org.apache.commons/commons-text implementation "org.apache.commons:commons-text:1.9"; // https://mvnrepository.com/artifact/org.yaml/snakeyaml // https://bitbucket.org/asomov/snakeyaml/src/default/ implementation "org.yaml:snakeyaml:1.28"; // ╔══════════════════════╗ // ║ Logging dependencies ║ // ╚══════════════════════╝ // SLF4J // https://mvnrepository.com/artifact/org.slf4j/slf4j-api implementation "org.slf4j:slf4j-api:1.7.32" // Log4j2 // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-bom // Not as per the Log4j2 documentation (couldn't get their way to work and it seems more recondite) // https://logging.apache.org/log4j/2.x/maven-artifacts.html implementation platform("org.apache.logging.log4j:log4j-bom:2.17.1") implementation "org.apache.logging.log4j:log4j-api" implementation "org.apache.logging.log4j:log4j-core" // SLF4J bridge for Log4j2 // Existing components that use SLF4J will have their logging routed to Log4j2 implementation "org.apache.logging.log4j:log4j-slf4j-impl" // ╔═══════════════════╗ // ║ Test dependencies ║ // ╚═══════════════════╝ // https://www.baeldung.com/junit-5-gradle testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2" // ╔═══════════════════════════╗ // ║ Test fixture dependencies ║ // ╚═══════════════════════════╝ testFixturesImplementation "org.slf4j:slf4j-api:1.7.32"
}
// ╔═══════════════════════════════════════════════════════════════════════════╗
// ║ Other configuration ║
// ╚═══════════════════════════════════════════════════════════════════════════╝
// Generate a sources JAR for the library
// Building Java Libraries Sample
java {
withSourcesJar()
}// Use JUnit 5 for tests
// Testing in Java & JVM projects
test {
useJUnitPlatform()
}// IDE configuration.
// Download the source code of jar dependencies.
// how to tell gradle to download all the source jars - Stack Overflow
idea {
module {
downloadSources = true
}
}// Add some entries to the manifest file
// Building Java Libraries Sample
tasks.named(“jar”) {
manifest {
attributes(“Implementation-Title”: project.name,
“Implementation-Version”: project.version)
}
}
Any help or insight appreciated. I’ve tried modifying the “test” sourceSet to include the files from the test fixtures - but without success. I’m not a Gradle guru, so maybe I just approached it incorrectly…
Don’t think its relevant, but the “:shared:utils” and “:shared:aws-api” modules are Git submodules.
Thank you for your time and attention