tdd

Data structure for Double Elmination Tournament

时间秒杀一切 提交于 2021-02-18 11:10:19
问题 I am in the process of converting my Tournament Organizer software, which allows the creation and manipulation of Double Elimination Tournaments, to use the MVVM design pattern so that it can be more easily tested. In doing so, I'm separating out the 'model' from some code in the UI that directly manipulates the bracket structure. This will be the third iteration of software I've written to handle tournaments. The first was written in PHP and stored the data in a database. The second version

Data structure for Double Elmination Tournament

我只是一个虾纸丫 提交于 2021-02-18 11:09:36
问题 I am in the process of converting my Tournament Organizer software, which allows the creation and manipulation of Double Elimination Tournaments, to use the MVVM design pattern so that it can be more easily tested. In doing so, I'm separating out the 'model' from some code in the UI that directly manipulates the bracket structure. This will be the third iteration of software I've written to handle tournaments. The first was written in PHP and stored the data in a database. The second version

How do I pass value from beforeEach() to test? Mocha/Chai

孤街醉人 提交于 2021-02-11 02:49:33
问题 How do I pass the dom object, from my beforeEach() function, to my tests? For example: describe('2) Key DOM elements exist', function() { beforeEach(function(done){ JSDOM.fromURL('http://localhost:3000/', ).then(dom => { this.hello = dom; }); done(); }); it('a) Header element is present', function() { console.log(hello); const header = dom.window.document.getElementById('header'); expect(header).to.exist; }) }); 回答1: The issue is that this is not bound to the callback function passed to

How do I pass value from beforeEach() to test? Mocha/Chai

时光怂恿深爱的人放手 提交于 2021-02-11 02:48:54
问题 How do I pass the dom object, from my beforeEach() function, to my tests? For example: describe('2) Key DOM elements exist', function() { beforeEach(function(done){ JSDOM.fromURL('http://localhost:3000/', ).then(dom => { this.hello = dom; }); done(); }); it('a) Header element is present', function() { console.log(hello); const header = dom.window.document.getElementById('header'); expect(header).to.exist; }) }); 回答1: The issue is that this is not bound to the callback function passed to

How do I pass value from beforeEach() to test? Mocha/Chai

依然范特西╮ 提交于 2021-02-11 02:48:19
问题 How do I pass the dom object, from my beforeEach() function, to my tests? For example: describe('2) Key DOM elements exist', function() { beforeEach(function(done){ JSDOM.fromURL('http://localhost:3000/', ).then(dom => { this.hello = dom; }); done(); }); it('a) Header element is present', function() { console.log(hello); const header = dom.window.document.getElementById('header'); expect(header).to.exist; }) }); 回答1: The issue is that this is not bound to the callback function passed to

What are different types of test doubles and their uses?

孤街浪徒 提交于 2021-02-08 07:43:50
问题 I was going through an online course on test driven development and came across the concept of test doubles. As per the definition of test double in the course : Test Doubles : Test doubles are objects that are used in unit tests as replacement to the real production system collaborators. I got an idea what test doubles mean. But then it was mentioned there are various types of test doubles. The ones mentioned in the course were : Dummy : Objects that can be passed around as necessary but do

What are different types of test doubles and their uses?

风格不统一 提交于 2021-02-08 07:43:28
问题 I was going through an online course on test driven development and came across the concept of test doubles. As per the definition of test double in the course : Test Doubles : Test doubles are objects that are used in unit tests as replacement to the real production system collaborators. I got an idea what test doubles mean. But then it was mentioned there are various types of test doubles. The ones mentioned in the course were : Dummy : Objects that can be passed around as necessary but do

How to mock the same method in Prophecy so it returns different response in each of its calls

你。 提交于 2021-02-07 20:35:44
问题 In pure PHPUnit mocking I can do something like this: $mock->expects($this->at(0)) ->method('isReady') ->will($this->returnValue(false)); $mock->expects($this->at(1)) ->method('isReady') ->will($this->returnValue(true)); I was not able to do the same thing using Prophecy. Is it possible? 回答1: You can use: $mock->isReady()->willReturn(false, true); Apparently it's not documented (see https://gist.github.com/gquemener/292e7c5a4bbb72fd48a8). 回答2: There is another documented way to do that. If

Should I create a new test method for each assertion?

烂漫一生 提交于 2021-02-07 14:30:21
问题 I know that this is subjective, but I'd like to follow the most common practice. Do you normally create one test method for each class method and stuff it with multiple assertions, or do you create one test method per assertion? For example, if I am testing a bank account's withdraw method, and I want make sure that an exception is thrown if the user tries to overdraw the account or withdraw a negative amount, should I create testOverdaw and testNegativeWithdrawal , or would I just combine

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

拟墨画扇 提交于 2021-02-07 12:11:33
问题 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