Giter Club home page Giter Club logo

Comments (4)

superbaobao avatar superbaobao commented on August 21, 2024

Final方法就是不希望你去修改。JDK中有大量final方法,spring中也有很多,我不觉得对测试有什么影响。不知道你所说的“脱离容器测试”是什么意思?URIBroker就是一个bean,你直接创建它就行了,不需要mock。

from citrus.

jilen avatar jilen commented on August 21, 2024

如果不是final,when(uriBrokerService.getURIBroker(anyString()).render()).thenReturn("http://foo.bar") ; 这样的mok会很easy

from citrus.

jilen avatar jilen commented on August 21, 2024

URIBroker broker = new GenericURIBroker();
broker.setBaseURI("http://foo.bar"); 好吧,GenericURIBroker创建的成不确实不高,不需要依赖webx

from citrus.

superbaobao avatar superbaobao commented on August 21, 2024

你这个代码即使对于URIBroker做成接口也是行不通的。

我给你个代码建议:(使用EasyMock)

import static org.easymock.EasyMock.*;

import com.alibaba.citrus.service.uribroker.URIBrokerService;
import com.alibaba.citrus.service.uribroker.uri.GenericURIBroker;
import com.alibaba.citrus.service.uribroker.uri.URIBroker;

public class Test {
public static void main(String[] args) {
URIBroker uri = new GenericURIBroker().setServerURI("http://aaa.com/bbb");

    URIBrokerService uris = createMock(URIBrokerService.class);

    expect(uris.getURIBroker("myuri")).andReturn(uri.fork()).anyTimes();
    replay(uris);

    URIBroker myuri = uris.getURIBroker("myuri");

    System.out.println(myuri.render());

    verify(uris);
}

}

在 2012-7-26,下午7:41,jilen [email protected] 写道:

如果不是final,when(uriBrokerService.getURIBroker(anyString()).render()).thenReturn("http://foo.bar") ; 这样的mok会很easy


Reply to this email directly or view it on GitHub:
#12 (comment)

from citrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.