Spring Web Business System single measurement using Jmockit for overlay mock

Source: Internet
Author: User

The spring business system generally uses a single case. Multilayer calls.

For example a call to B,b calls C.

To test the method of a, you need to boast a multilayer mock C method.

Using Jmockit's Nonstrictexpectations

@Servicepublic class A {    @Autowired    b b;    public void Method () {        b.method ();    }}

@Servicepublic class B {    @Autowired    IC C;    public void Method () {        System.out.println ("b=" + C.method ());}    }

@Servicepublic class C implements IC {    @Override public    Integer method () {        System.out.println ("123"); C13/>return 1;    }}

Public interface ICS {public    Integer method ();}

@RunWith (Springjunit4classrunner.class) @TransactionConfiguration (TransactionManager = "Kuaipaytransactionmanager ", Defaultrollback = True) @Transactional @contextconfiguration (locations = {" Classpath: Kuaipay-api-impl-test-application.xml "}) @TestExecutionListeners ({ Dependencyinjectiontestexecutionlistener.class, Dirtiescontexttestexecutionlistener.class,                         Transactionaltestexecutionlistener.class}) public class Jmockittestmock  {    @Autowired    a  ;    The interface is mock, corresponding to the Dubbo    @Autowired    IC IC;    Overlay mock. Replace the class directly. Jmockit's Divine Power    @Test public    void Testmockit () {        new <span style= "color: #ff0000;" >NonStrictExpectations</span> (IC) {            {                ic.method ();                result = integer.valueof (5);            }        };        A.method ();    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Spring Web Business System single measurement using Jmockit for overlay mock

Related Article

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.