Gradle Test passes in eclipse but fails on gradle build / Spring Boot

test-tag
buildship
eclipse

(Yousra M) #1

Hi there,

When I test my spring boot project using eclipse whetheir I run it as a junit test or a gradle test, it passes, however when I test it using the command:

gradle build

or

gradle test

All my tests fails. Here is my build.gradle:

buildscript {
ext {
springBootVersion = ‘1.5.8.RELEASE’
}
repositories {
mavenCentral()
}
dependencies {
classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)
}
}

apply plugin: 'java’
apply plugin: 'eclipse’
apply plugin: 'idea’
apply plugin: ‘org.springframework.boot’

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar {
baseName = rootProject.name
version = project.version
}

repositories {
mavenCentral()
}

dependencies {
compile(‘org.springframework.boot:spring-boot-starter-web’)
compile(‘org.springframework.boot:spring-boot-starter-data-jpa’)
compile(‘org.springframework:spring-jdbc’)
compile(‘mysql:mysql-connector-java’)
compile(‘javax.validation:validation-api:2.0.1.Final’)
compile(‘org.hibernate:hibernate-core:5.2.2.Final’)
compile(‘org.hibernate:hibernate-tools:5.2.0.Final’)
testCompile(‘com.h2database:h2:1.4.196’)
testCompile(‘org.springframework.boot:spring-boot-starter-test’)
testCompile(‘org.springframework.security:spring-security-test’)

}

This is a test example:

@ RunWith(SpringRunner.class)
@ SpringBootTest(classes = Application.class)
@ DataJpaTest
@ ActiveProfiles(“test”)
public class IEmployeeRepositoryTest {

@ Autowired
private TestEntityManager entityManager;

@ Autowired
private IEmployeeRepository employeeRepository;

  //my tests

}

I should also mention this is my project structure:

src
----main
------java
------resources
--------application.yml
--------schema.sql
----test
------java
------resources
--------application-test.yml
--------schema-test.sql

I’ve been stuck on this for days, I appreciate all the help I can get.


(Donát Csikós) #2

What is the expected and the actual outcome of those tests? Without that, I can only guess.

We recently added better Spring Boot app support for Buildship. The enhancements work automatically: you only need to make sure you use Buildship 2.2 and Gradle 3.4 or newer. If you already use those versions, then I’d need an example project exhibiting the problem.