Spring boot Unit Testing


(Fazeem) #1

Hi ,

The Spring boot application we are developing doesn’t need Tomcat Dependency as we are deploying the war file in JBOSS server.so we excluded dependency in gradle using the following configuration
configurations {
compile.exclude module: ‘spring-boot-starter-tomcat’
}

But during the Build JUnit test cases are failing as we excluded the Tomcat dependency.

Is there any way to include the ‘spring-boot-starter-tomcat’ library only during the test cases execution?(I tried to include the library using testCompile() and testRunTime() feature but it is not working)


(James Justinic) #2

Exclusions apply to the configuration specified AND any configuration that extends it. The testCompile and testRuntime configurations extend from the compile configuration, so you will not be able to add a dependency to the test configurations that you have explicitly excluded from the compile configuration.

You could create a configuration, add the dependency, and add it to your test class path, but there is no need to do that extra work. Since you are building a war file, the providedCompile and providedRuntime configurations already give you ability to add a dependency that is not included in the war. This is built in to Gradle.

If you’re also applying the Spring Boot plugin, you might want to review the modifications it makes so that you don’t get a bootable war if you don’t want that.


(Fazeem) #3

Hi Justinic,

The provided solution working as expected

Thanks,
Fazeem