Use gradle to run the integration test

Source: Internet
Author: User

IfGradleThe constructed project isWebProject may contain someIntegration TestAnd functional testing. These tests andUnit TestThe difference is that before running the service, you must start the Web Service locally and automatically close the Web service after testing.

To start the Web Service locally, we can use the built-in jetty plug-in of gradle. Jetty is a lightweight Web Container with fast execution, simple configuration, and convenient remote debugging. To enable jetty, you only need to add reference to this plug-in build. gradle.

Apply Plugin: 'jetty'

You can configure the war package name, startup port, and other attributes.

Apply Plugin: 'jetty'

Httpport = 9876

[Jettyrun, jettyrunwar, jettystop] *. stopport = 9966

[Jettyrun, jettyrunwar, jettystop] *. stopkey = 'stopkey'

We need to separate integration testing from general unit testing. Because the unit test does not need to start the Web service in advance, so that it can be executed quickly and get faster feedback. Generally, the extension name of the unit test isTest. Java, with the extension integrationtest. java.

Configure the test set for unit test execution.

Test {

Include '**/* test. class'

Exclude '**/* integrationtest. class'

}

Create a new task to run the integration test.

Build. gradle

Task inttest (type: Test, dependson: Test ){

Include '**/* integrationtest. class'

Dofirst {

Jettyrun. Daemon = true

Jettyrun.exe cute ()

}

Dolast {

Jettystop.exe cute ()

}

}

The above code first creates a task named inttest, which is of the test Type and depends on the test task. This integration test only runs the test class named integrationtest. Before running the test, start the jetty server in the background mode and call the jettystop task to stop the jetty service.

To enable inttest task to run during gradle build, you can add dependency on inttest.

Build. dependson inttest

In this way, the integration test is also run when gradle build is run. Web services are automatically started and closed before and after the integration test.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.