unit-testing

Issue with stubbing/mocking the method with makes a DB call

∥☆過路亽.° 提交于 2021-02-10 06:22:08
问题 I am having issue with Mocking a JDBC call using the MockitoJUnitRunner. Somehow Mockito is not mocking the actual call even though I have below subbing line into the test class. when(readOnlyJdbcTemplate.query(anyString(), any(Object[].class), any(int[].class), any(FeatureCollectionResponseExtractor.class))).thenReturn(actual); Very similar mocking is working in another class for very similar type of method. The only difference between them is my other class does have 3 parameters instead of

Disable/accept test storage service in Espresso

偶尔善良 提交于 2021-02-10 05:45:48
问题 As can be seen in AndroidX Test 1.3.0 alpha04 release notes: Include the test storage service in the test services Unfortunately, this makes standard connectedDebugAndroidTest to fail because this screen is getting displayed: Choose what to allow TestServices to access And this requires my interaction in order to proceed with UI testing. This makes me to hang with already quite old 1.3.0-alpha03 artifacts, although 1.3.0-beta01 is already available. Question: How to accepts this permission

How should I unit test MySQL queries?

我的未来我决定 提交于 2021-02-10 05:12:49
问题 I'm building some unit tests for my Python module which interfaces with a MySQL database via SQLAlchemy. From reading around I gather the best way to do this is to create a test database that I can query as if it was the real thing. I've done this however how should I test the existing queries in the module as they currently all point at the live database? The only idea I'd come up with was to do something like the following: def run_query(engine, db_name='live_db') engine.execute(f'SELECT *

AutoMock - How to unit test with Keyed Registrations?

拥有回忆 提交于 2021-02-10 04:53:30
问题 I'm having trouble writing tests around a factory that uses Autofac keyed registrations. In an Autofac module, I register things like this: builder.RegisterType<TypeAMessageHandler>().As<IMessageHandler>() .Keyed<IMessageHandler>(MessageTypeEnum.A); builder.RegisterType<TypeBMessageHandler>().As<IMessageHandler>() .Keyed<IMessageHandler>(MessageTypeEnum.B); builder.RegisterType<MessageHandlerFactory().As<IMessageHandlerFactory>(); Then the constructor for the factory gets a nice Index

AutoMock - How to unit test with Keyed Registrations?

筅森魡賤 提交于 2021-02-10 04:52:09
问题 I'm having trouble writing tests around a factory that uses Autofac keyed registrations. In an Autofac module, I register things like this: builder.RegisterType<TypeAMessageHandler>().As<IMessageHandler>() .Keyed<IMessageHandler>(MessageTypeEnum.A); builder.RegisterType<TypeBMessageHandler>().As<IMessageHandler>() .Keyed<IMessageHandler>(MessageTypeEnum.B); builder.RegisterType<MessageHandlerFactory().As<IMessageHandlerFactory>(); Then the constructor for the factory gets a nice Index

How to test that an inner function has been called from an imported function? (with Jest.js)

天大地大妈咪最大 提交于 2021-02-09 10:58:34
问题 I'm having issues with Jest testing that a closure (an inner function) has been called after calling the outer function. I've tried using the spyOn with no positive result. This seems to be a relatively simple problem, to which I haven't found any results from googling. // helper.js export const bar = () => {} export const foo = () => { bar(); //How do I test that this has been called? } //helper.test.js import * as H from 'helper'; const barSpy = jest.spyOn(H, 'bar'); H.foo(); expect(barSpy)

How to test that an inner function has been called from an imported function? (with Jest.js)

老子叫甜甜 提交于 2021-02-09 10:58:32
问题 I'm having issues with Jest testing that a closure (an inner function) has been called after calling the outer function. I've tried using the spyOn with no positive result. This seems to be a relatively simple problem, to which I haven't found any results from googling. // helper.js export const bar = () => {} export const foo = () => { bar(); //How do I test that this has been called? } //helper.test.js import * as H from 'helper'; const barSpy = jest.spyOn(H, 'bar'); H.foo(); expect(barSpy)

Why am I getting the “Expression is not assignable” error?

时间秒杀一切 提交于 2021-02-08 21:19:25
问题 I made a class with private name, units sold, and units remaining. I made two class methods that return, units sold and units remaining as ints. I want to sort the units sold from greatest to least, but I get errors as I explain in the comments. What am I doing wrong, is it something very obvious? #include <iostream> #include <string> #include <fstream> using namespace std; const int MAX_SIZE = 1000; const char FILE_NAME[14] = "inventory.txt"; //make an Item class class Item { private: string

How to use Moq framework to unit test azure service fabrics?

[亡魂溺海] 提交于 2021-02-08 15:36:37
问题 I am planning to use Moq for unit testing my azure service fabric application. I saw some of the examples here https://github.com/Azure-Samples/service-fabric-dotnet-web-reference-app/blob/master/ReferenceApp/Inventory.UnitTests/InventoryServiceTests.cs. The test I saw seems like actually writing to reliable dictionary and not mocking. Is there way to mock the add/remove from reliable dictionary? How do I unit test something like below public async Task<bool> AddItem(MyItem item) { var items

Can't create test client during unit test of Flask app

耗尽温柔 提交于 2021-02-08 14:10:31
问题 I am trying to find out how to run a test on a function which grabs a variable value from session['user_id'] . This is the specific test method: def test_myProfile_page(self): with app.test_client() as c: with c.session_transaction() as sess: sess['user_id'] = '1' rv = c.get('/myProfile') assert 'My Profile' in rv.data This is the view being tested: @app.route('/myProfile') def myProfile(): if not session.get('logged_in'): return render_template('login.html') else: profileID = session['user