tdd

Useful design patterns for unit testing/TDD?

谁说我不能喝 提交于 2019-12-20 08:17:29
问题 Reading this question has helped me solidify some of the problems I've always had with unit-testing, TDD, et al. Since coming across the TDD approach to development I knew that it was the right path to follow. Reading various tutorials helped me understand how to make a start, but they have always been very simplistic - not really something that one can apply to an active project. The best I've managed is writing tests around small parts of my code - things like libraries, that are used by

Applying TDD when the application is 100% CRUD

喜夏-厌秋 提交于 2019-12-20 08:06:53
问题 I routinely run into this problem, and I'm not sure how to get past this hurdle. I really want to start learning and applying Test-Driven-Development (or BDD, or whatever) but it seems like every application I do where I want to apply is it pretty much only standard database CRUD stuff, and I'm not sure how to go about applying it. The objects pretty much don't do anything apart from being persisted to a database; there is no complex logic that needs to be tested. There is a gateway that I'll

TSQLT unit test - The data types text and text are incompatible in the equal to operator

前提是你 提交于 2019-12-20 04:14:09
问题 I am getting this error from AssertEqualsTable "The data types text and text are incompatible in the equal to operator." then "The 'TableCompare' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead." select * into #Actual from [dbo].[InvoiceOut]; --make expected table an empty table of #actual's structure because we truncate so it should be empty. SELECT TOP(0) * INTO #Expected FROM #Actual; EXEC tSQLt.AssertEqualsTable '#Expected', '

Do shoulda-matchers' ActiveRecord matchers violate the “test behavior not implementation” rule?

久未见 提交于 2019-12-19 22:09:12
问题 For example, if I am using should validate_presence_of in my spec, that's only testing that I have the validate_presence_of piece of code inside my model, and that's testing implementation. More importantly, isn't that spec totally useless for testing the real problem, which is "if I don't fill out a certain field, will the model be saved successfully?" 回答1: Some of shoulda-matchers' matchers don't test implementation, they test behavior. For example, look at the source for allow_value (which

How can I test void methods? [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-19 19:47:15
问题 This question already has answers here : Unit testing void methods? (11 answers) Closed 6 years ago . I have some void methods and I need to test them, but I'm not sure about how to do it. I just know how to test methods that return something, using Assert. Someone knows how to do it? Do you guys know some links with exercices in this style? 回答1: You can test two things: State changes after void method call (state-based testing) Interaction with dependencies during void method call

How can I test void methods? [duplicate]

大兔子大兔子 提交于 2019-12-19 19:46:09
问题 This question already has answers here : Unit testing void methods? (11 answers) Closed 6 years ago . I have some void methods and I need to test them, but I'm not sure about how to do it. I just know how to test methods that return something, using Assert. Someone knows how to do it? Do you guys know some links with exercices in this style? 回答1: You can test two things: State changes after void method call (state-based testing) Interaction with dependencies during void method call

mocha with nodejs assert hangs/timeouts for assert(false) instead of error

我的未来我决定 提交于 2019-12-19 17:46:48
问题 I have this kind of a mocha test: describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) → // I make the assertions here // assert(false) assert(articleList.length > 1) ) done() ) The problem is, whenever I do assert(false) , the test hangs until the

mocha with nodejs assert hangs/timeouts for assert(false) instead of error

一世执手 提交于 2019-12-19 17:46:04
问题 I have this kind of a mocha test: describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) → // I make the assertions here // assert(false) assert(articleList.length > 1) ) done() ) The problem is, whenever I do assert(false) , the test hangs until the

Should I unit-test with data that should not be passed in a function (invalid input)?

﹥>﹥吖頭↗ 提交于 2019-12-19 17:45:11
问题 I am trying to use TDD for my coding practice. I would like to ask should I test with a data that should not happen in a function BUT this data may possibly break your program. Here is one of a easy example to illustrate to what I ask : a ROBOT function that has a one INT parameter. In this function I know that the valid range would only be 0-100. If -1, 101 is used, the function will be break. function ROBOT (int num){ ... ... ... return result; } So I decided some automated test cases for

Convenient method in GoogleTest for a double comparison of not equal?

那年仲夏 提交于 2019-12-19 17:35:05
问题 I'm looking for something similar to the ASSERT_EQ / ASSERT_NE for ASSERT_DOUBLE_EQ. Maybe I'm missing an easy way of doing this without having a ASSERT_DOUBLE_NE? 回答1: You can use the companion mocking framework Google Mock. It has a powerful library of matchers (a la Hamcrest), which you can use with the EXPECT_THAT/ASSERT_THAT macros: EXPECT_THAT(value, FloatEq(1)); EXPECT_THAT(another_value, Not(DoubleEq(3.14))); 回答2: It looks like you're out of luck. However, you could add one yourself.