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