Using JUnit Test in the spring environment

Source: Internet
Author: User

Using the spring framework to make it easy to write code with separate tests for some code snippet code without having to run the entire environment for testing, the JUnit test is introduced to facilitate the testing of the local code block.

1, first guide package, such as MAVEN project: where JUnit needs at least in the 4.12 version, or will be error

  

2 Create a new test package and set the test package to test Source Root

3, the new class plus annotations, load the test class, load the spring configuration file, because spring Auto-injection helps us inject the image, so it can be obtained directly through annotations when used, but the spring configuration file should have the declaration of the relevant Bean object, in order to inject the use in the test.

4, you can test directly in the class, you can also let the subclass inherit the class, the subclass inherits, then does not need the annotation introduction context.

Using JUnit Test in the spring environment

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.