mocking

Python Testing - Reset all mocks?

青春壹個敷衍的年華 提交于 2021-02-06 11:27:33
问题 When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks at the end of every file / module to avoid inter-file test pollution? It seems like something that is mocked in one Python test file remains mocked in other file with the same return value, which means my mocks are persisting between tests and files (when a patch decorator or with patch block is NOT used). Is there any way around

Python Testing - Reset all mocks?

北战南征 提交于 2021-02-06 11:26:46
问题 When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks at the end of every file / module to avoid inter-file test pollution? It seems like something that is mocked in one Python test file remains mocked in other file with the same return value, which means my mocks are persisting between tests and files (when a patch decorator or with patch block is NOT used). Is there any way around

Python Testing - Reset all mocks?

邮差的信 提交于 2021-02-06 11:25:12
问题 When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks at the end of every file / module to avoid inter-file test pollution? It seems like something that is mocked in one Python test file remains mocked in other file with the same return value, which means my mocks are persisting between tests and files (when a patch decorator or with patch block is NOT used). Is there any way around

Python Testing - Reset all mocks?

点点圈 提交于 2021-02-06 11:25:12
问题 When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks at the end of every file / module to avoid inter-file test pollution? It seems like something that is mocked in one Python test file remains mocked in other file with the same return value, which means my mocks are persisting between tests and files (when a patch decorator or with patch block is NOT used). Is there any way around

Mocking PDO with phpunit

笑着哭i 提交于 2021-02-06 09:58:23
问题 I am trying to mock PDO object to use when writing some tests with phpunit, but I find it pretty complicated and can't find too much documentation about it. I created this xml structure: <dataset> <table name="providers"> <column>id</column> <column>name</column> <column>description</column> <row> <value>1</value> <value>provdier_1</value> <value>phpunit first provider</value> </row> </table> </dataset> and now I want to query providers table and get the data back but I just cant figure out

How to mock/replace getter function of object with Jest?

浪尽此生 提交于 2021-02-05 20:40:11
问题 In Sinon I can do the following: var myObj = { prop: 'foo' }; sinon.stub(myObj, 'prop').get(function getterFn() { return 'bar'; }); myObj.prop; // 'bar' But how can I do the same with Jest? I can't just overwrite the function with something like jest.fn() , because it won't replace the getter "can't set the value of get" 回答1: You could use Object.defineProperty Object.defineProperty(myObj, 'prop', { get: jest.fn(() => 'bar'), set: jest.fn() }); 回答2: For anyone else stumbling across this

Create React App doesn't properly mock modules from __mocks__ directory

空扰寡人 提交于 2021-02-05 11:36:22
问题 I have a working example with Jest and mocks from __mocks__ directory that works : With simple Jest setup // package.json { "name": "a", "version": "1.0.0", "main": "index.js", "scripts": { "test": "jest" }, ... "devDependencies": { "jest": "^26.6.3" }, "dependencies": { "@octokit/rest": "^18.0.12" } } And then /index.js : const { Octokit } = require("@octokit/rest"); const octokit = new Octokit(); module.exports.foo = function() { return octokit.repos.listForOrg({ org: "octokit", type:

How do you mock and test the same function in C/C++ with FFF and Google Test?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:35:13
问题 I am exploring TDD (Test Driven Development) to test the code that I am writing in C and C++. I have chosen to use Google Test as the unit test framework. I have chosen to use FFF as the mocking framework. I have written a few tests and run them and it works great. But I have come across an issue that I have not been able to find any reference to online and I was hoping the community could help me (and this would help others as well). The issue I have is that I would like to write a test for

How to test SimpleJdbcCall

狂风中的少年 提交于 2021-02-05 08:55:18
问题 I need to create test for this code. @Autowired JdbcTemplate jdbcTemplate; public List<Row> getData(int id) { // Preconditions here SimpleJdbcCall getCall = new SimpleJdbcCall(jdbcTemplate) .withSchemaName(SCHEMA) .withProcedureName(SP) .declareParameters( // ... ) .returningResultSet("result", (RowMapper<QuestionAnswerRow>) (rs, rowNum) -> .....); MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("id", id); // other parameters here Map queryRes = getCall.execute

How to test SimpleJdbcCall

半世苍凉 提交于 2021-02-05 08:54:28
问题 I need to create test for this code. @Autowired JdbcTemplate jdbcTemplate; public List<Row> getData(int id) { // Preconditions here SimpleJdbcCall getCall = new SimpleJdbcCall(jdbcTemplate) .withSchemaName(SCHEMA) .withProcedureName(SP) .declareParameters( // ... ) .returningResultSet("result", (RowMapper<QuestionAnswerRow>) (rs, rowNum) -> .....); MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("id", id); // other parameters here Map queryRes = getCall.execute