testing

How can I block external connections with RSpec & Capybara?

僤鯓⒐⒋嵵緔 提交于 2020-05-26 13:40:31
问题 With my Rails project, I would like to write tests non-ideal conditions such as lack of internet connection or timeouts. For example, I am using a gem to contact an API and would like to make sure that I handle the error correctly if there is a connection issue between my app and the external API. I can do this already by making a fixture with VCR and removing the response from the "cassette". However, this has drawbacks: It has to be done manually. The cassettes can not be gitignored if I am

How can I block external connections with RSpec & Capybara?

孤者浪人 提交于 2020-05-26 13:38:48
问题 With my Rails project, I would like to write tests non-ideal conditions such as lack of internet connection or timeouts. For example, I am using a gem to contact an API and would like to make sure that I handle the error correctly if there is a connection issue between my app and the external API. I can do this already by making a fixture with VCR and removing the response from the "cassette". However, this has drawbacks: It has to be done manually. The cassettes can not be gitignored if I am

Pytest - error vs fail

走远了吗. 提交于 2020-05-26 10:37:14
问题 Im migrating from PyUnit to Pytest, and I found, that Pytest, unlike PyUnit, does not distinguish fails and errors in test report in quick report while running tests (where dots are printed). How to teach Pytest do do it? UPDATE Seems like it is valid only for PyUnit tests executed with Pytest, thanks to flub for the clue. Code: import unittest class TestErrorFail(unittest.TestCase): def test_error(self): raise Exception('oops') def test_fail(self): self.assertTrue(False) Output: ============

How to keep Unit tests and Integrations tests separate in pytest

泪湿孤枕 提交于 2020-05-26 10:32:08
问题 According to Wikipedia and various articles it is best practice to divide tests into Unit tests (run first) and Integration tests (run second), where Unit tests are typically very fast and should be run with every build in a CI environment, however Integration tests take longer to run and should be more of a daily run. Is there a way to divide these in pytest? Most projects don't seem to have multiple test folders, so is there a way to make sure I only run Unit, Integration or both according

How to keep Unit tests and Integrations tests separate in pytest

。_饼干妹妹 提交于 2020-05-26 10:31:20
问题 According to Wikipedia and various articles it is best practice to divide tests into Unit tests (run first) and Integration tests (run second), where Unit tests are typically very fast and should be run with every build in a CI environment, however Integration tests take longer to run and should be more of a daily run. Is there a way to divide these in pytest? Most projects don't seem to have multiple test folders, so is there a way to make sure I only run Unit, Integration or both according

How to mocking created time in sqlalchemy?

守給你的承諾、 提交于 2020-05-26 02:43:10
问题 I use SQLAlchemy in my Flask application. In my tests I try mocking auto time create and update for my entries. But I don't understand how it work for SQLAlchemy. For example I try mocking datetime creating with freezgun, but is failure. For example: class Entry(db.Model): __tablename__ = 'entries' created = db.Column(db.DateTime(), default=db.func.now()) updated = db.Column(db.DateTime(), default=db.func.now(), onupdate=db.func.now()) class ViewTestCase(AppliactionTestCase): def test(self):

How to mock window.navigator.language using jest

[亡魂溺海] 提交于 2020-05-25 06:37:26
问题 I am trying to mock the window.navigator.language attribute in the browser in my jest unit tests so I can test that the content on my page is using the correct language I have found people online using this: Object.defineProperty(window.navigator, 'language', {value: 'es', configurable: true}); I have set it right at the top of my test file and it is working there however, when I redefine in an individual test (and people set to make sure configurable was set to true) it wont redefine it and

Test planning/documentation/management tools

自古美人都是妖i 提交于 2020-05-24 08:26:26
问题 I'm looking for a good, preferably free, test planning and documentation tool. Ideally something that will keep track of which tests have been run against which software version, with reporting ability. There's a whole bunch of tools listed here but are there any others, and which ones have you had the best experience with? (You do run tests, right?) UPDATE 2008-01-29 So far TestLink and Fitness have been mentioned. A related question yielded also a link to the ReadySet project, an open

Mock React useRef or a function inside a functional component with enzyme and jest?

不打扰是莪最后的温柔 提交于 2020-05-24 05:55:11
问题 Codesanbox link - includes working component Child2.js and working test Child2.test.js Child2.js import React, { useRef } from "react"; export default function Child2() { const divRef = useRef(); function getDivWidth() { if (divRef.current) { console.log(divRef.current); } return divRef.current ? divRef.current.offsetWidth : ""; } function getDivText() { const divWidth = getDivWidth(); if (divWidth) { if (divWidth > 100) { return "ABC"; } return "123"; } return "123"; } return ( <> <div id=

Mock React useRef or a function inside a functional component with enzyme and jest?

人走茶凉 提交于 2020-05-24 05:55:02
问题 Codesanbox link - includes working component Child2.js and working test Child2.test.js Child2.js import React, { useRef } from "react"; export default function Child2() { const divRef = useRef(); function getDivWidth() { if (divRef.current) { console.log(divRef.current); } return divRef.current ? divRef.current.offsetWidth : ""; } function getDivText() { const divWidth = getDivWidth(); if (divWidth) { if (divWidth > 100) { return "ABC"; } return "123"; } return "123"; } return ( <> <div id=