I am trying to write integration tests for my service.
I have tried to write a simple test as my first test. My WebControllerIT class is as follows:
#RunWith(SpringRunner.class)
#SpringBootTest(
classes = SocialInteractionApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebControllerIT {
#LocalServerPort private int webServerPort;
#Autowired private AppUserRepository AppUserRepository;
#Autowired private WebController webController;
private RestTemplate restTemplate = new RestTemplate();
private String createURLWithPort(String uri) {
return "http://localhost:" + webServerPort + uri;
}
#Test
public void testSetNewAppUser() {
HttpEntity<String> entity = new HttpEntity<String>(null,null);
ResponseEntity<String> response =
restTemplate.exchange(
createURLWithPort("/{RobsAndroid}/setNewAppUser/{Rob}"),
HttpMethod.GET,
entity,
String.class);
String expected = "New AppUser: " + "RobsAndroid"+ " set OK.";
assertEquals(expected,response.getBody());
assertEquals(HttpStatus.OK,response.getStatusCode());
}
}
However, I am getting an error:
Execution failed for task ':integrationTest'.
> No tests found for given includes: [com.socialinteraction.componenttests.WebControllerIT.testSetNewAppUser](filter.includeTestsMatching)
I can't seem to work out what's going on, any ideas?
To give some more context, I wasn't sure how to start with component testing. This included: where they should be located, what dependencies they should have, how to run them in the gradle build etc. I followed a tutorial and my build.gradle file has ended up as follows:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.socialinteraction'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
integrationTestImplementation.extendsFrom testImplementation
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')
// testCompile "org.powermock:powermock-module-junit4:1.6.4"
// testCompile 'org.mockito:mockito-core:2.7.22'
implementation 'org.jetbrains:annotations:15.0'
implementation 'junit:junit:4.12'
implementation 'org.testng:testng:6.9.6'
implementation 'junit:junit:4.12'
implementation 'junit:junit:4.12'
implementation 'org.testng:testng:6.9.6'
}
test {
useJUnitPlatform()
}
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
I essentially made sure the integration test dependencies were inherited from unit tests, there was a new intergrationTest type and that this was ran in the build after unit tests.
Side question - not sure testRuntime, testImplementation and other dependencies type are all needed/right, so a good link to explain these would be great if someone has one?
Thanks so much for your help!
try to add useJUnitPlatform() inside your task desc:
task integrationTest(type: Test) {
useJUnitPlatform()
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
It works for me.
Related
I can't resolve the groovy.json.JsonSlurper in the build.gradle file with Intellij, does anyone know how to fix it?
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
task sample() {
doLast {
sample();
}
}
import groovy.json.JsonSlurper
def sample(){
def json = new JsonSlurper().parseText('{"a":"b"}')
println(json);
}
You missing the needed dependency.
Add org.codehaus.groovy:groovy-json:3.0.9 in dependencies section so ti will look like
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'org.codehaus.groovy:groovy-json:3.0.9'
}
And then you can test with CLI as gradle sample or ./gradlew sample and it will return {a=b}
Here is my build.gradle , I had upgraded gradle 5.x to 6.9.2 and while executing gradleW build I am getting below error.
[ant:taskdef] Could not load definitions from resource org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties. It could not be found.
Task :compileJava FAILED
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\9796te\Company\2021\December\27\01\hopper-api\build.gradle' line: 180
What went wrong:
Execution failed for task ':compileJava'.
Problem: failed to create task or type iajc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
And here is the build.gradle file:
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'com.adarshr.test-logger' version '1.6.0'
id 'com.gorylenko.gradle-git-properties' version '2.0.0'
id 'org.sonarqube' version '2.7'
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'com.bp.hopper.Application'
sourceCompatibility = 11
targetCompatibility = 11
jar {
enabled = true
archiveBaseName = 'hopper-api'
archiveVersion = '0.1'
}
bootJar {
classifier = 'application'
}
sourceSets {
integration
}
configurations {
aspects
compile.extendsFrom aspects
}
springBoot {
buildInfo()
}
testlogger {
theme 'mocha'
}
sonarqube {
properties {
property "sonar.projectKey", "com.bp.WellHopper:hopper-api"
}
}
repositories {
mavenCentral()
mavenLocal() // For those who can't access internal BP repos
//jcenter()
maven { url 'http://dml-prime.bpweb.bp.com:8088/artifactory/bp-upstream-devops-lib-release-local' }
}
// Non-spring boot versions
ext.versions = [
accesstokenvalidator: '2.1.4g',
onbehalfof: '2.1.4f',
clientcredentials: '2.1.4h',
swagger: '2.9.2',
applicationinsights: '2.6.0', // if you change this then change web.config and replace the updated jar in project root
commonsio: '2.6',
mssqljdbc: '7.2.2.jre8',
xlxsstreamer: '1.2.0',
guava: '27.1-jre',
beanutils: '1.9.3',
tika: '1.20',
jacksondatatypejts: '2.4',
azurestorage: '8.2.0',
azurekeyvault: '1.2.4',
azure: '1.34.0',
hibernatesearch: '5.10.5.Final',
reflections: '0.9.11',
awaitility: '4.0.3',
microsoftgraph: '1.2.0',
dozer: '6.5.0',
lombok: '1.18.12',
hibernatetypes: '2.10.0',
qpid: '0.55.0',
javaobjectdiff: '0.95'
]
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'org.apache.logging.log4j') {
details.useVersion '2.17.0'
}
}
}
dependencies {
annotationProcessor "org.projectlombok:lombok:$versions.lombok"
aspects "org.springframework:spring-aspects"
implementation "org.aspectj:aspectjrt"
implementation "org.aspectj:aspectjtools"
implementation "org.aspectj:aspectjweaver"
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework:spring-jms'
implementation 'org.springframework.data:spring-data-envers'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5'
implementation ("org.hibernate:hibernate-spatial") {
exclude group: 'org.postgresql', module: 'postgresql'
}
implementation "org.hibernate:hibernate-search-orm:$versions.hibernatesearch"
implementation "com.vladmihalcea:hibernate-types-5:$versions.hibernatetypes"
implementation "com.microsoft.azure:azure-storage:$versions.azurestorage"
implementation "com.microsoft.graph:microsoft-graph:$versions.microsoftgraph"
implementation "org.projectlombok:lombok:$versions.lombok"
implementation 'org.flywaydb:flyway-core'
implementation "org.apache.tika:tika-core:$versions.tika"
implementation "com.bedatadriven:jackson-datatype-jts:$versions.jacksondatatypejts"
implementation "org.reflections:reflections:$versions.reflections"
implementation "com.google.guava:guava:$versions.guava"
implementation 'javax.xml.bind:jaxb-api'
implementation 'org.glassfish.jaxb:jaxb-runtime'
implementation "commons-io:commons-io:$versions.commonsio"
implementation "com.microsoft.sqlserver:mssql-jdbc:$versions.mssqljdbc"
implementation "com.monitorjbl:xlsx-streamer:$versions.xlxsstreamer"
implementation "io.springfox:springfox-swagger2:$versions.swagger"
implementation "io.springfox:springfox-swagger-ui:$versions.swagger"
implementation "com.bp:access-token-validator:$versions.accesstokenvalidator"
implementation "com.bp:access-token-on-behalf-of:$versions.onbehalfof"
implementation "com.bp:access-token-client-credentials:$versions.clientcredentials"
implementation "com.microsoft.azure:azure-keyvault:$versions.azurekeyvault"
implementation "com.microsoft.azure:azure:$versions.azure"
implementation "com.microsoft.azure:applicationinsights-web:$versions.applicationinsights"
implementation "com.microsoft.azure:applicationinsights-logging-logback:$versions.applicationinsights"
implementation 'org.jsoup:jsoup:1.11.2' // safe html
implementation ("commons-beanutils:commons-beanutils:$versions.beanutils") {
exclude group: 'commons-logging', module: 'commons-logging'
}
implementation 'org.slf4j:jcl-over-slf4j'
implementation "com.github.dozermapper:dozer-spring-boot-starter:$versions.dozer"
implementation "org.apache.qpid:qpid-jms-client:$versions.qpid"
implementation "de.danielbechler:java-object-diff:$versions.javaobjectdiff"
testAnnotationProcessor "org.projectlombok:lombok:$versions.lombok"
testimplementation ('org.springframework.boot:spring-boot-starter-test')
testimplementation 'com.vmlens:concurrent-junit:1.0.2'
testimplementation 'io.github.benas:random-beans:3.7.0'
testimplementation "com.flipkart.zjsonpatch:zjsonpatch:0.4.11"
testRuntimeOnly 'com.h2database:h2'
integrationAnnotationProcessor "org.projectlombok:lombok:$versions.lombok"
integrationimplementation 'org.springframework.boot:spring-boot-starter-test'
integrationimplementation 'org.springframework.boot:spring-boot-starter-jdbc'
integrationimplementation 'org.springframework.boot:spring-boot-starter-json'
integrationimplementation "org.projectlombok:lombok:$versions.lombok"
integrationimplementation "io.rest-assured:rest-assured"
integrationimplementation "com.monitorjbl:xlsx-streamer:$versions.xlxsstreamer"
integrationimplementation "com.microsoft.sqlserver:mssql-jdbc:$versions.mssqljdbc"
integrationimplementation "com.google.guava:guava:$versions.guava"
integrationimplementation "commons-beanutils:commons-beanutils:$versions.beanutils"
integrationimplementation ('org.hibernate:hibernate-spatial') {
exclude group: 'org.postgresql', module: 'postgresql'
}
integrationimplementation "com.bedatadriven:jackson-datatype-jts:$versions.jacksondatatypejts"
integrationimplementation "org.awaitility:awaitility:$versions.awaitility"
integrationimplementation "org.reflections:reflections:$versions.reflections"
integrationimplementation "com.github.dozermapper:dozer-spring-boot-starter:$versions.dozer"
integrationimplementation "com.flipkart.zjsonpatch:zjsonpatch:0.4.11"
}
compileJava {
println 'Java Version: ' + JavaVersion.current()
println 'Java Source Compatibility: ' + sourceCompatibility
println 'Java Target Compatibility: ' + targetCompatibility
doLast {
ant.taskdef(resource: 'org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties', classpath: configurations.compile.asPath)
ant.iajc(inpath: sourceSets.main.output.classesDirs.asPath, classpath: configurations.compile.asPath, aspectPath: configurations.aspects.asPath, destDir: sourceSets.main.output.classesDirs.asPath)
}
}
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integration.output
classpath = sourceSets.integration.runtimeClasspath
outputs.upToDateWhen { false }
}
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
minHeapSize = "512m"
maxHeapSize = "2g"
jvmArgs = [
"-Dfile.encoding=UTF-8",
"-Duser.timezone=UTC"
]
}
bootRun {
if (project.hasProperty('jvmArgs')) {
jvmArgs = (project.jvmArgs.split("\\s+" as Closure) as List)
} else {
jvmArgs = [
"-Dapp.security.enable=true",
"-Djava.net.preferIPv4Stack=true",
"-Dfile.encoding=UTF-8",
"-Duser.timezone=UTC"
]
}
}
def createLocalDatabaseSql = "create database hopper\n" +
"go\n" +
"create login bp with password = 'bp', check_policy = off\n" +
"go\n" +
"use hopper\n" +
"go\n" +
"create user bp for login bp\n" +
"go\n" +
"sp_addrolemember 'db_owner', 'bp'\n" +
"go\n" +
"exit\n"
def dropLocalDatabaseSql = "drop database hopper\n" +
"go\n" +
"drop login bp\n" +
"go\n" +
"exit\n"
task createLocalDatabase(type: Exec) {
standardInput = new ByteArrayInputStream(createLocalDatabaseSql.getBytes('UTF-8'))
commandLine 'cmd', '/c', 'sqlcmd'
}
task createLocalDatabaseDocker(type: Exec) {
standardInput = new ByteArrayInputStream(createLocalDatabaseSql.getBytes('UTF-8'))
commandLine 'sqlcmd', '-U', 'sa', '-P', 'Passw0rd'
}
task dropLocalDatabase(type: Exec) {
standardInput = new ByteArrayInputStream(dropLocalDatabaseSql.getBytes('UTF-8'))
commandLine 'cmd', '/c', 'sqlcmd'
}
task dropLocalDatabaseDocker(type: Exec) {
standardInput = new ByteArrayInputStream(dropLocalDatabaseSql.getBytes('UTF-8'))
commandLine 'sqlcmd', '-U', 'sa', '-P', 'Passw0rd'
}
eclipse {
classpath {
plusConfigurations.add configurations.integrationCompile
plusConfigurations.add configurations.integrationRuntime
}
}
I was following here. I used postgresql instead of h2. I was able to build the project with some additional fields.
I created a package database under com.example.demo, but it was still empty after project was built.
build.gradle:
buildscript {
ext {
springBootVersion = '2.4.2'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.jooq:jooq-codegen:3.14.4'
classpath 'org.postgresql:postgresql:42.2.18'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.*
task generate {
def configuration = new Configuration()
configuration
.withJdbc(new Jdbc()
.withDriver('org.postgresql.Driver')
.withUrl('jdbc:postgresql://localhost:5432/vertx')
.withUser('postgres')
.withPassword('postgres'))
.withGenerator(new Generator()
.withDatabase(new Database().withInputSchema('public'))
.withGenerate(new Generate()
.withPojos(true)
.withDaos(true))
.withTarget(new Target()
.withPackageName('com.example.demo.database')
.withDirectory('src/main/java')))
doLast {
GenerationTool.generate(configuration)
}
}
Is there something I am missing? Why can I not see pojos and daos in database package? My database has only one table with 2 columns.
BUILD SUCCESSFULL when I type ./gradlew generate, but nothing gets generated.
You can try ./gradlew generate --info command, which will give you more information about the build process.
My gradle script is quite similar to yours. By using above command, I find out that the classes are actually generated, but in a different folder /Users/{MyUserName}/.gradle/daemon/7.1.1/src/main/java.
So I have to explicitly set the output directory with def outputDirectory = projectDir.toString() + '/src/main/java'.
This works for me
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.jooq:jooq-codegen:3.16.2'
classpath 'mysql:mysql-connector-java:8.0.27'
}
}
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
if(JavaVersion.current() != JavaVersion.VERSION_11){
throw new GradleException("This build must be run with java 11")
}
repositories {
mavenCentral()
}
group = 'snorlax'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
//create a fat Jar with all dependencies
jar {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes "Main-Class": "com.snorlax.userservice.MainApplication"
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
dependencies {
// Spring boot
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// RDS Connection
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java:8.0.27'
// AWS secretes manager
implementation 'com.amazonaws.secretsmanager:aws-secretsmanager-jdbc:1.0.6'
// JOOQ
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.jooq:jooq-meta:3.16.2'
compileOnly 'org.jooq:jooq-codegen:3.16.2'
}
test {
useJUnitPlatform()
}
/************************
jooq code generation
*************************/
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.*;
task generate {
def outputDirectory = projectDir.toString() + '/src/main/java'
def configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver('com.mysql.cj.jdbc.Driver')
.withUrl('jdbc:mysql://127.0.0.1:3306/snorlaxRds')
.withUser('root')
.withPassword('123456'))
.withGenerator(new Generator()
.withDatabase(new Database().withInputSchema("snorlaxRds"))
.withGenerate(new Generate()
.withPojos(true)
.withDaos(true))
.withTarget(new Target()
.withPackageName('snorlax.userservice.database')
.withDirectory(outputDirectory)));
doLast {
GenerationTool.generate(configuration)
}
}
Your file looks okay. I had a similar issue (while using maven). Try three things (that worked for me):
check case of the schema in "withInputSchema" property. Try to pass uppercase PUBLIC.
try to change 'src/main/java' to './src/main/java'
add "includes" and pass .* in it (to generate for all tables in the schema)
I am trying to combine a Spring Boot backend api and a React frontend app into one single jar.
I was able to build a jar file containing both by following this article (https://medium.com/xebia-engineering/a-minimalistic-guide-to-building-and-deploying-monolithic-spring-boot-react-applications-39440035b27) but the frontend jar ends up in BOOT-INF/lib/frontend.jar instead of META-INF/resources. How can I create a jar file with the webjar in the right directory so it can render a React page?
frontend/build.gradle
plugins {
id "com.moowork.node" version "1.3.1"
}
apply plugin: "java"
apply plugin: "com.moowork.node"
node {
version = "12.9.1"
download = true
}
task bundle(type: NpmTask, dependsOn: npmInstall) {
args = ["run", "build"]
}
task uiTest(type: NpmTask) {
environment = ["CI": "true"]
args = ["run", "test"]
}
task run(type: NpmTask) {
args = ["start"]
}
check.dependsOn(test)
jar.dependsOn(bundle)
task webjar(type: Jar) {
from(fileTree("build")) {
into "META-INF/resources"
}
}
check.dependsOn(test)
jar.dependsOn(bundle)
jar.finalizedBy("webjar")
backend/build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
jar {
manifest {
attributes "Main-Class": "com.example.kasahararestapi.StockCheckAppApplication"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class" // whatever Ant pattern matches your test class files
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.social:spring-social-github:1.0.0.M4'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.0'
implementation 'io.jsonwebtoken:jjwt:0.9.0'
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.807')
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-mail:1.2.0.RELEASE'
implementation 'org.modelmapper:modelmapper:2.3.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
implementation project(path: ':frontend', configuration: 'default')
}
setting.gradle
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'stock_check_app'
include 'backend'
include 'frontend'
I have this root build.gradle
repositories {
jcenter()
}
subprojects {
apply plugin: 'java'
group 'me.someone'
version '1.0.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
}
}
Then I have this child build.gradle
plugins {
id 'java-library'
id 'eclipse'
id "org.springframework.boot" version "2.0.1.RELEASE"
id 'io.spring.dependency-management' version "1.0.5.RELEASE"
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile project(':foo-jar')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.18.3'
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
test {
java.srcDir file('src/int/java')
}
itest {
java {
srcDir file('src/itest/java')
}
//resources.srcDir 'src/itest/resources'
}
}
test {
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
exceptionFormat = 'full'
}
}
task itest(type: Test) {
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
exceptionFormat = 'full'
}
itest.mustRunAfter test
}
check.dependsOn itest
bootRun {
main = 'me.someone.BarServiceApplication'
}
The issue is unit test runs twice but not the integration test. Why is unit test running twice but not integration test? My understanding is when I provided the source folder of integration test, it should run the integration test as well.
Your task itest needs to have its testClassesDirs configured, that is why it is currently running your unit tests twice. It might also need the classpath configured.
And you should have a look at the Gradle documentation on how to do integration tests for all the details.