stub

How to stub Python methods without Mock

末鹿安然 提交于 2019-12-02 23:51:12
I'm a C# dev moving into some Python stuff, so I don't know what I'm doing just yet. I've read that you don't really need Dependency Injection with Python. I've been told you can instantiate objects in your code and have them run the way you want, however, you can point methods on those objects to my own stubs defined in my tests - supposedly without mocks. Is this true? I've tried to do it and can't quite get it working. How is this actually done? How do I stub a method in Python without a mocking library? Here's a basic example. Note that the production getData() method is never called. It

Can RSpec stubbed method return different values in sequence?

随声附和 提交于 2019-12-02 17:49:11
I have a model Family with a method location which merges the location outputs of other objects, Members. (Members are associated with families, but that's not important here.) For example, given member_1 has location == 'San Diego (traveling, returns 15 May)' member_2 has location == 'San Diego' Family.location might return 'San Diego (member_1 traveling, returns 15 May)' The specifics are unimportant. To simplify the testing of Family.location, I want to stub Member.location. However, I need it to return two different (specified) values as in the example above. Ideally, these would be based

“Duplicate file name” for same WSDL namespace when using web-service from different sub-domains

放肆的年华 提交于 2019-12-02 09:03:13
问题 Preface We are providing customers with our service API. Each customer has own subdomain (e.g. sergii.ourwebsite.com) and own WSDL URL, it looks like http://sergii.ourwebsite.com/api/bsapi.cfc?wsdl Also, all the websites (including API, of course) using the same codebase. Problem Say, two applications on same CF-server. This can easily happen, because some of customer websites are hosted on our servers. Both trying to use own API WSDL, say: http://sergii.ourwebsite.com/api/bsapi.cfc?wsdl http

ContentResolver.requestSync in Sync Adapter is not working in Android

瘦欲@ 提交于 2019-12-01 16:57:16
I am trying to write a sync adapter with 'StubProvider' and 'StubAuthenticator', i followed the offical guidelines, my code is running without any errors but 'onPerformSync()' is NOT getting called, i tried everything but no use. My full project can be downloaded from https://www.dropbox.com/s/48bgj3wweehaieu/MyApplication.zip?dl=0 Here are the classes I am using: Class MainActivity public class MainActivity extends FragmentActivity implements View.OnClickListener { // Constants // The authority for the sync adapter's content provider public static final String AUTHORITY = "com.syncadaptertest

How do I include test classes and configuration in my war for integration testing using maven?

て烟熏妆下的殇ゞ 提交于 2019-12-01 00:29:04
问题 I currently have a maven web project that I am attempting to write integration tests for. For the structure of the project, I've defined test stubs under src/test/java , whilst the spring bean definitions for these stubs sit under src/test/resources . What I would like to do, is that when I build my war artifact I'd like all of the test stub classes to be compiled and included in the war along with the spring bean definition files. I've tried to do it with the maven war plugin but the only

Android Local Service Sample, bindservice(), and ServiceConnection()

痴心易碎 提交于 2019-11-30 23:18:02
I have a question which is related to this question that was asked by @mnish about a year ago. Please have a look at his question and code. He implements a ServiceConnection() and passes it to bindService(). This follows the Local Service Sample in the Service documentation near the top. I want to implement the Local Service Sample, so I am trying to add some details from @mnish question/answer. In ServiceConnection() @mnish has this line that confuses me: mService = ILocService.Stub.asInterface(iservice); I understand @mnish wrote this code, but does anybody have any idea what ILocService is

node express es6 sinon stubbing middleware not working

夙愿已清 提交于 2019-11-30 22:58:03
I am writing the mocha unit test for the my express router. I found that however I try to stub the middleware, it still execute the middleware code. Here is my router & test, could anyone figure out? Router: import { aMiddleware, bMiddleware, cMiddleware } from '../middleware.js'; router.post('/url', aMiddleware, bMiddleware, cMiddleware, function(req, res) { ... } Middleware: AuthMiddleware.aMiddleware = async (req, res, next) => { console.log('in real middleware'); next(); } Test: var authMiddleware = require('../../middleware/auth.js'); describe('Test', async () => { before(function (done)

How to stub/mock JDBC ResultSet to work both with Java 5 and 6?

你离开我真会死。 提交于 2019-11-30 20:01:22
I'm testing some of my classes working with JDBC statements etc and now I got problem with JDBC ResultSet interface: The software should run both with Java 5 and Java 6 and hence the tests should also be run with both versions. Unfortunately Java 6 has introduced a bunch of new methods (which is still not a big deal) that return a bunch of new classes/interfaces, which makes the things more difficult. (see Frank Carver’s Punch Barrel - Java 6 breaks JDBC for example) Before finding out these version differences, I considered between stubbing and mocking and ended up with stubbing because the

Stubbing WebSocket in JavaScript with Jasmine

喜你入骨 提交于 2019-11-30 14:18:48
I try to test if onmessage is a proper function. Here is a test: describe(".init(address, window)", function() { beforeEach(function() { address = 'ws://test.address'; window = {}; e = { data: {} } spyOn(window, 'WebSocket').and.returnValue(function() {return {onmessage: null}}); spyOn(subject, 'handleMessage'); }); it("should create a WebSocket client which connects to the given address", function() { subject.init(address, window); expect(window.WebSocket).toHaveBeenCalledWith(address); }); it("should have onmessage method overriden with a function which handles message", function() { ws =

How to use stubs in JUnit and Java?

浪尽此生 提交于 2019-11-30 06:57:02
I have worked with JUnit and Mocks but I'm wondering, what are the differences between Mocks and Stubs in JUnit and how to use Stubs in JUnit, Java? And as Mocks that have EasyMock, Mockito and so on, what does Stubs uses in Java? Please give some example code for Stubs in Java. Sergey Lagutin To use stubs in junit you don't need any frameworks. If you want to stub some interface just implement it: interface Service { String doSomething(); } class ServiceStub implements Service { public String doSomething(){ return "my stubbed return"; } } Then create new stub object and inject it to tested