stub

What is an easy way to stub / dummy a restful web service?

痴心易碎 提交于 2019-11-28 17:52:52
I want to create an android application, this application will make RESTful calls to a web service to obtain some data. I know what the RESTful interface will be, but I don't want the hassle of creating my own implementation. Is there an easy way to create a stub RESTful web service that will return some static data without having to write a full blown WS application to do this? Probably the best thing to do is create a mock for the REST web service service while you're developing your application code and then replace it with code to call the actual web service returning "real" data, once

rspec: How to stub an instance method called by constructor?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 17:50:57
class A def initialize @x = do_something end def do_something 42 end end How can I stub do_something in rspec, before the original implementation is called (thus assigning 42 to @x )? And without changing the implementation, of course. Orion Edwards Here's the commit which adds the feature to rspec - This was on May 25 2008. With this you can do A.any_instance.stub(do_something: 23) However, the latest gem version of rspec (1.1.11, October 2008) doesn't have this patch in it. This ticket states that they yanked it out for maintenance reasons, and an alternative solution hasn't yet been

How do I stub things in MiniTest?

余生长醉 提交于 2019-11-28 16:18:36
Within my test I want to stub a canned response for any instance of a class. It might look like something like: Book.stubs(:title).any_instance().returns("War and Peace") Then whenever I call @book.title it returns "War and Peace". Is there a way to do this within MiniTest? If yes, can you give me an example code snippet? Or do I need something like mocha? MiniTest does support Mocks but Mocks are overkill for what I need. Panic # Create a mock object book = MiniTest::Mock.new # Set the mock to expect :title, return "War and Piece" # (note that unless we call book.verify, minitest will # not

Android 跨进程通信基础

妖精的绣舞 提交于 2019-11-28 15:21:47
Android跨进程通信基础——Binder, BinderProxy, parcel, parcelable, Stub, Stub.Proxy (该文章最早于2013年6月7日发表于有道云笔记 进入阅读 ) 百度、google 过很多文章,都没能找到能够从 API 使用者角度简单描述 Binder,BinderProxy,Parcel,Parcelable,Stub,Stub.Proxy 之间关系的文章,要么高深莫测,要么混乱不清。最终决定还是自己动手,看源码,看文档,现总结如下: Binder,BinderProxy 形成了进程间通信的基础,相当于公路桥梁; Parcel 在 IBinder 基础上传输数据,相当于运输工具; Parcelable 基本数据类型和实现了 Parcelable 接口的复合数据类型才可被 Parcel 传输,相当于摆放整齐、安检合格的货物; Stub,Stub.Proxy 实现跨进程调用的接口,相当于收发货方。 注:Binder,BinderProxy 都实现了 IBinder 接口 下面以 Activity 与 Service 通信为例来分析其运行机制。 示例目的:通过跨进程调用方式在 Activity 进程端调用 Service 进程端的方法。这些方法由接口 RemoteSSO 定义。这里假设两者是运行在不同进程的(也可以运行在相同进程

What does “to stub” mean in programming?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 15:15:33
For example, what does it mean in this quote? Integrating with an external API is almost a guarantee in any modern web app. To effectively test such integration, you need to stub it out. A good stub should be easy to create and consistently up-to-date with actual, current API responses. In this post, we’ll outline a testing strategy using stubs for an external API. A stub is a controllable replacement for an Existing Dependency (or collaborator) in the system. By using a stub, you can test your code without dealing with the dependency directly. External Dependency - Existing Dependency: It is

Prevent stubbing of equals method

折月煮酒 提交于 2019-11-28 12:05:49
I would like to test my class' equals() method but Mockito seems to be calling the stub version every time. My test is as follows; PluginResourceAdapter adapter = mock (PluginResourceAdapter.class); PluginResourceAdapter other = mock (PluginResourceAdapter.class); when(adapter.getNumberOfEndpointActivation()).thenReturn(1); when(other.getNumberOfEndpointActivation()).thenReturn(0); boolean result = adapter.equals(other); assertFalse(result); I know I cannot stub the equals method which means Mockito should be calling my real implementation but its not. I have also tried this: when (adapter

What is an easy way to stub / dummy a restful web service?

醉酒当歌 提交于 2019-11-27 20:08:00
问题 I want to create an android application, this application will make RESTful calls to a web service to obtain some data. I know what the RESTful interface will be, but I don't want the hassle of creating my own implementation. Is there an easy way to create a stub RESTful web service that will return some static data without having to write a full blown WS application to do this? 回答1: Probably the best thing to do is create a mock for the REST web service service while you're developing your

Difference between Mock / Stub / Spy in Spock test framework

試著忘記壹切 提交于 2019-11-27 17:01:04
I don't understand the difference between Mock, Stub, and Spy in Spock testing and the tutorials I have been looking at online don't explain them in detail. Attention: I am going to oversimplify and maybe even slightly falsify in the upcoming paragraphs. For more detailed info see Martin Fowler's website . A mock is a dummy class replacing a real one, returning something like null or 0 for each method call. You use a mock if you need a dummy instance of a complex class which would otherwise use external resources like network connections, files or databases or maybe use dozens of other objects

What is a “Stub”?

耗尽温柔 提交于 2019-11-27 16:49:11
So, carrying on with my new years resolution to get more in to TDD, I am now starting to work more with Rhino Mocks . One thing I am keen to do is to make sure I really grok what I am getting in to, so I wanted to check my understanding of what I have seen so far (and I thought it would be good to get it up here as a resource). What is a "Stub"? Martin Fowler wrote an excellent article on this subject. From that article: Meszaros uses the term Test Double as the generic term for any kind of pretend object used in place of a real object for testing purposes. The name comes from the notion of a

java.net.ConnectException :connection timed out: connect?

家住魔仙堡 提交于 2019-11-26 22:35:22
I have used RMI in my code : import java.rmi.*; public interface AddServerIntf extends Remote { double add(double d1,double d2) throws RemoteException; } import java.rmi.*; import java.rmi.server.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { public AddServerImpl() throws RemoteException { } public double add(double d1,double d2) throws RemoteException { return d1+d2; } } import java.net.*; import java.rmi.*; public class AddServer { public static void main(String args[]) { try { AddServerImpl addServerImpl=new AddServerImpl(); Naming.rebind("AddServer"