stub

Unit testing of Jar methods in java

佐手、 提交于 2019-12-11 12:34:21
问题 I'm using Apache POI methods for writing to excel sheets in java. I have to do unit-testing for the methods which I have written. I have used many methods of Apache POI. Should I stub all the methods of the different object classes of Apache POI? Example: I have created wrapper methods for writing to cell which are using Apache POI methods. protected void writeCell(int rowNum, int colNum, String value, Sheet sheet) { if(value == null) { return; } Row row = sheet.getRow(rowNum); Cell cell =

Unit Test for n tier architecture

故事扮演 提交于 2019-12-11 03:24:13
问题 I am using 3 tier architecture: Controller, Business, and Data Layer. In my Data Layer, I am making a call to an Sql Server Database by passing Connection String and other necessary parameters. I have to write unit tests for the Controller layer and Business layer. I want to write a stub (fake repository) from which I would return the hard coded values/result. When I write a test for business layer, the logic should call this stub instead of the real database. How can I write the code in the

Rspec : stubbing ActiveStorage download method

青春壹個敷衍的年華 提交于 2019-12-11 02:31:39
问题 I work on a system that stores cached data on S3 with ActiveStorage before using it for something else. In my spec, I want to stub the download method of this file, and load a specific file for testing purpose. allow(user.cached_data).to receive(:download) .and_return(read_json_file('sample_data.json')) ( read_json_file is a spec helper that File.read then JSON.parse a data file.) I get this error : #<ActiveStorage::Attached::One:0x00007f9304a934d8 @name="cached_data", @record=#<User id: 4,

How to stub i18n_scope for mocking ActiveRecord::RecordInvalid on Rails 4 rspec 3.3.0?

拜拜、爱过 提交于 2019-12-10 20:59:35
问题 I have tried this code but it raises the error: NameError: uninitialized constant RSpec::Mocks::Mock RSpec::Mocks::Mock.stub(:i18n_scope).and_return(:activerecord) model = double(:model, errors: double(:errors, full_messages: [])) ActiveRecord::RecordInvalid.new(model) How can I stub i18n_scope ? 回答1: To answer your question, you have to stub RSpec::Mocks::Double because that's the class of the instance you're actually passing to ActiveRecord::RecordInvalid. However, that won't work because

RSpec Stubbing: return in a sequence

纵然是瞬间 提交于 2019-12-10 17:09:43
问题 I know the following things work: returning a parameter subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] } and a sequence (it will return a 0 on the first call, and the second time "exit") subject.should_receive(:get_user_choice).and_return(0, "exit") But how to combine them? what if I would like to return the parameter the first time and then return "exit" 回答1: Alternatively: subject.should_receive(:get_user_choice).ordered.and_return { |choices| choices.to_a[0] } subject

Stub a controller helper method in a template helper spec

牧云@^-^@ 提交于 2019-12-10 13:23:29
问题 My ApplicationController exposes a method (e.g. sort_direction ) to the view templates by using helper_method :sort_direction . I then use this method in another method (e.g. sort_link ) of a view helper ( application_helper.rb ). When testing the sort_link method with RSpec (in application_helper_spec.rb ) I have to stub sort_direction as the test seems to run complete independent from the controllers (and thereby by its to the view templates exposed methods). Unfortunately I could not find

Which is the best isolation framework for Java? JMock, Easymock, Mockito, or other?

こ雲淡風輕ζ 提交于 2019-12-10 13:06:04
问题 I realize this has been asked before, but the last time was in mid 2008. If you were starting a new project right now, which one would you use and why? What are their strengths/weaknesses regarding readability, usability, maintainability, and overall robustness? 回答1: I have used Easymock earlier, but now I'm using Mockito. I found Mockito simpler as compared to Easymock. For the detailed comparison of Easymock and Mockito you can refer here 回答2: To explain our motivation, jMock is an

sinon.js stub - can you call more than one callback on a single stubbed function?

☆樱花仙子☆ 提交于 2019-12-10 03:14:41
问题 If I have a stub for a function that takes 2 callbacks, how can I wire up sinon.js to call both callbacks when the stubbed function is invoked? For example - here's function that I want to stub which takes 2 functions as arguments: function stubThisThing(one, two) { ... one and two are functions ... ... contents stubbed by sinon.js ... } I can use sinon to call either one of the arguments : stubbedThing.callsArg(0); or stubbedThing.callsArg(1); but I can't seem to get both to be called . If I

Android unit testing with Junit: testing network/bluetooth resources

随声附和 提交于 2019-12-10 00:56:39
问题 I am slowly becoming obsessed with unit testing. I am trying to develop as much software as I can using test-driven development. I am using JUnit to unit test my android applications. I have been working on an app that uses bluetooth and am having a hard time unit testing it. I have an Activity that uses BluetoothAdapter to obtain a list of paired and discovered devices. Although it works, I would like to know how to unit test it. To get the list of paired devices, I call getBondedDevices()

Please explain how to create PHP's Phar stubs

[亡魂溺海] 提交于 2019-12-09 05:08:46
问题 I'm trying to create a very simple PHP CLI application that can be run as a phar file from the command line: # php myProject.phar This is what I've tried so far: My Project My project is in a directory called MyProject and it has these two files in it: |-- createPhar.php `-- bootstrap.php bootstrap.php The bootstrap.php file contains this: <?php print phpversion() . PHP_EOL; print 'i am some script' . PHP_EOL; When I run this script from my Ubuntu command line: # cd MyProject # php bootstrap