[JAVA] Integration Test with Gradle

If the automated test involves a database, etc., it will take a long time to execute. Let's divide it into unit tests and integration tests so that you can easily execute unit tests. It seems that the accuracy of the test will improve if you can test in the combined state every time, but if it takes time and you do not test, it will be overwhelming.

If you use Gradle, the article https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/ was good, so just make a note of the conclusion.

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

task integrationTest(type: Test) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }

Write it like a unit test, place it in src / integration-test / java, and run it with gradle integrationTest. The library used only by integrationTest is specified in dependencies with ╩╗integrationTestCompile`.

Recommended Posts

Integration Test with Gradle
Remote debugging with Gradle test
Output test coverage with clover + gradle
JUnit 5 gradle test fails with lombok annotation
Java automated test implementation with JUnit 5 + Gradle
Use ProGuard with Gradle
Build and test Java + Gradle applications with Wercker
Install Gradle with ubuntu16.04
DataNucleus starting with Gradle
[Rails] Test with RSpec
Test Nokogiri with Rspec.
Automatically test with Gauge
Load test with JMeter
Unit test with Junit.
Use WebJars with Gradle
Get started with Gradle
Use jlink with gradle
WebAPI unit test and integration test with SpringBoot + Junit5, 4 patterns
Java multi-project creation with Gradle
Gradle + Kotlin-Generate jar with DSL
Test Web API with junit
Test Active Strage with RSpec
Lombok not working with Gradle5
Test GraphQL resolver with rspec
Use log4j2 with YAML + Gradle
Hello World with SpringBoot / Gradle
Build a Java project with Gradle
REST API test with REST Assured Part 2
I tried using JOOQ with Gradle
Test with RSpec + Capybara + selenium + chromedriver
I can't install lombok with Gradle.
[Java] Test private methods with JUnit
[Java] LINE integration with Spring Boot
Copy and paste test with RSpec
Test list inclusion relationships with AssertJ
Test Spring framework controller with Junit
Develop Processing with IntelliJ + Kotlin + Gradle
Let's unit test with [rails] Rspec!
Spring Boot gradle build with Docker
MASCHINE test Linear Regression with Multiple Variables
With EqualsVerifier, the equals () test was instant
[Ruby on Rails] View test with RSpec
API integration from Java with Jersey Client
How to filter JUnit Test in Gradle
Control test order in Junit4 with enumeration
Java EE test (CDI / interceptor) with Arquillian
Perform transaction confirmation test with Spring Boot
CICS-Run Java applications-(3) Build management with Gradle
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
How to test private scope with JUnit
Configure a multi-project with subdirectories in Gradle
rails test fails with database reference error
Download JDK with Gradle and make JRE
Add scripts to distributions created with gradle
Automate integration testing with Maven Failsafe plugin