Springboottest unit tests encountered pits

Source: Internet
Author: User
The project structure is a service provided by spring Boot to provide RPC interface, and Dubbo is used;

Recently need to use unit testing, found that the same card is there, the implementation of the test method, seemingly blocked;

Unit Test class:

@RunWith (Springrunner.class)
@SpringBootTest (webenvironment= SpringBootTest.WebEnvironment.NONE, classes = Application.class)
public class Tagtest {
	@Test
	public void Test () {
	System.out.println ("***************");
	}
}

Looking for a long time, after many practices and tracking source code analysis, found to execute into the Dubboservicelatchcommandlinerunner, in the method run blocked;


Package com.wacai.springboot.dubbo.commands;

Import Com.wacai.goodies.lifecycle.ShutdownLatch;
Import Org.springframework.boot.CommandLineRunner;


public class Dubboservicelatchcommandlinerunner implements Commandlinerunner {

    private String domain = " Com.wacai.lifecycles ";

    @Override public
    void Run (String ... args) throws Exception {
        Shutdownlatch latch = new Shutdownlatch (GetDomain () );
        Latch.await ();  This will cause blocking
    } public


    String GetDomain () {
        return domain;
    }

    public void SetDomain (String domain) {
        this.domain = domain;
    }
}

Later, the following dependencies in the Maven configuration file are commented out, and then the unit test can be run.

<dependency>
    <groupId>com.wacai</groupId>
    <artifactId> spring-boot-starter-dubbo</artifactid>
    <version>1.0.3</version>
</dependency >



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.