tdd

When to use a unit testing framework (vs. just using asserts)?

孤街醉人 提交于 2021-02-07 12:09:28
问题 Using a small (currently at 150 loc, probably less than 500 when finished) C project I'm working on, I'm teaching myself test driven development. Based on some stuff I've found on the web - especially these slides by Olve Maudal, I've just been using asserts in my unit tests. Since I'm just learning tdd, I have thus far avoided the overhead of also learning a unit testing framework such as cunit. At this point, my thinking is that the additional learning curve - even if shallow - of a

Using mock objects outside of testing, bad practice?

瘦欲@ 提交于 2021-02-07 03:40:28
问题 I'm working on a project where there is a lot of external service messaging. A good way to describe it in only a slightly "hyperbolas" way would be an application where the system has to send messages to the Flicker API, the Facebook API, and the Netflix API. To support disconnected scenarios, logging concerns, developer usability, configuration, etc... I've experimented using an approach which heavily uses generics and expression trees. The end result looks like this: Messenger<NetflixApi>

Using mock objects outside of testing, bad practice?

青春壹個敷衍的年華 提交于 2021-02-07 03:38:16
问题 I'm working on a project where there is a lot of external service messaging. A good way to describe it in only a slightly "hyperbolas" way would be an application where the system has to send messages to the Flicker API, the Facebook API, and the Netflix API. To support disconnected scenarios, logging concerns, developer usability, configuration, etc... I've experimented using an approach which heavily uses generics and expression trees. The end result looks like this: Messenger<NetflixApi>

Do you write your unit tests before or after coding a piece of functionality? [closed]

偶尔善良 提交于 2021-02-05 20:22:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I was wondering when most people wrote their unit tests, if at all. I usually write tests after writing my initial code to make sure

Go: build error when compiling unit tests (I'm trying to mock influxdb types)

一世执手 提交于 2021-01-29 08:00:50
问题 I'm just starting with go language. My mini-project successfully reads data from InfluxDB. Problem: when I import my package (which uses InfluxDB) into my unit test package, the build fails. "Production" code: package data import client "github.com/influxdata/influxdb1-client/v2" func FunctionToTest() {} // To make import necessary, unused for now func createClient() (client.Client, error) { return client.NewHTTPClient(client.HTTPConfig{Addr: addr}) } Unit test: package data_test import ( "..

TDD/testing CSS and HTML

浪尽此生 提交于 2021-01-28 06:02:00
问题 I am stuck at this point below: '''selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .has-error''' I tried to find a solution related to ".has-error" in order to get one of the functional tests via TDD to pass. Anyone ever experienced being stuck with that? Am I doing something wrong or missing a very little point? Your help would be appreciated! Related code between my template/selenium: Python part: self.wait_for(lambda: self.assertEqual(self.browser.find

Rails Rspec controller testing with nested resources

岁酱吖の 提交于 2021-01-28 04:48:44
问题 I have nested resources: resources :requests do resources :responses end and want to write controller test for response model. When I try to write: RSpec.describe ResponsesController, type: :controller do describe 'GET #show' do before do @testrequest = Request.create @testresponse = @testrequest.responses.create get :show, request_id: @testrequest.id, id: @testresponse.id end it 'show specific response selected by id if user owner of response or user owner of parent request' do expect

Is there an rspec test for exact length of an attribute?

寵の児 提交于 2020-12-04 17:27:17
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could

Is there an rspec test for exact length of an attribute?

半城伤御伤魂 提交于 2020-12-04 17:25:57
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could

Is there an rspec test for exact length of an attribute?

孤街醉人 提交于 2020-12-04 17:24:19
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could