tdd

How to design code for testability

南楼画角 提交于 2019-12-23 09:34:06
问题 I have been looking at using TDD and implementing proper testing (only just started to learn how much better it makes your life) in any of my projects that I create in the future. So for the last couple of days I have been floating around on SO trying to learn about how to design your application for testability, but I still seem to be struggling with some of the ideas. I have read a lot that you should program against interfaces rather than classes . The main problem I'm having is, how many

Testing Remove method without a call to Add method

强颜欢笑 提交于 2019-12-23 07:06:36
问题 I am writing test for a class thats manage trees of Tag objects: public class Tag { public virtual int Id { get; set; } public virtual string Description{ get; set; } private IList<Tag> children = new List<Tag>(); public virtual IEnumerable<Tag> Children { get {return children .ToArray();} } public void AddChildTag(Tag child) { children.Add(child); } public void RemoveChildTag(Tag child) { children.Remove(child); } } As you can see the only mode to set the parent property is via the

Is there a concurrency problem here? How to test it during development?

半世苍凉 提交于 2019-12-23 05:41:26
问题 Scenario: There exists 'n' teams who each work on their virtual 'wall' (like facebook's wall). Each team sees only their own wall and the posts on it. The posts can be edited by the author of the post or another team member (if so configured. Assuming this is indeed the case since it's a must have). Design/technology decisions: RESTful web-app using Restlet+ Glassfish/Java + Mysql (EDIT: Using Apache DBUtils for DB access. No ORM - seemed an overkill) Question: Multiple teams log on T1, T2

Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

◇◆丶佛笑我妖孽 提交于 2019-12-23 04:48:08
问题 This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD). Thanks all. 回答1: Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex. I tried to implement a testing repository which was also a disaster. Trying to

Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

纵然是瞬间 提交于 2019-12-23 04:48:00
问题 This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD). Thanks all. 回答1: Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex. I tried to implement a testing repository which was also a disaster. Trying to

Could current approach to TDD in Servlets be optimized?

人走茶凉 提交于 2019-12-23 02:30:17
问题 The current approach is creating HTML in a ServletTest, run the test, change the Servlet until the test turns into green. However, it feels like that this approach to TDD in Servlets is devious and more time-consuming than TDD ordinary Java classes as HTML created in the ServletTest is copied to the Servlet for the most part and subsequently changed regarding the format (e.g. removing backslashes) instead of testing the output in a Test for ordinary Java Classes and writing most of the code

Mocking DbContext for TDD Repository

℡╲_俬逩灬. 提交于 2019-12-23 00:50:48
问题 Trying to Mock my EF Context which is coupled to my Repository. Im using Moq, trying to setup a mocked Context and pass it into the Repository by the constructor. After that Im calling the Add method, to simply add a new object which I after that try to Assert by checking if the context i passed in has changed state... Error Im getting is a NullReference Exception and I guess its because my mocking isn't correct.. This is the code: Test with not working mock [TestClass] public class

Mocking DbContext for TDD Repository

﹥>﹥吖頭↗ 提交于 2019-12-23 00:50:08
问题 Trying to Mock my EF Context which is coupled to my Repository. Im using Moq, trying to setup a mocked Context and pass it into the Repository by the constructor. After that Im calling the Add method, to simply add a new object which I after that try to Assert by checking if the context i passed in has changed state... Error Im getting is a NullReference Exception and I guess its because my mocking isn't correct.. This is the code: Test with not working mock [TestClass] public class

TDD: Unit Testing Asynchronous Calls

夙愿已清 提交于 2019-12-22 14:05:57
问题 guys: I'm working on an application, and building it with unit testing. However, I'm now in a situation where I need to test asynchronous calls. For example, - (void)testUserInfoBecomesValidWhenUserIsBuiltSuccessfully { if ( ![userBuilder userInfoUpToDate] ) { [userBuilder buildUser]; } STAssertTrue([userBuilder userInfoUpToDate], @"User information is not valid before building the user"); } What is the general practice for testing such things? userInfoUpToDate is expected to be updated

Swift TDD & async URLSession - how to test?

末鹿安然 提交于 2019-12-22 11:14:02
问题 I try to get familiar with TDD. How can I test URLSession calls which are asynchronous ? Which XCAssert better to use and where, in which stage ? My first thought was to create a function, that has URLSession inside it, and inside this function set bool flag to true and then test it in XCAssertTrue. Or another thought was to return fake data synchronously after calling function which contains USLSession code. 回答1: Nice question. I think it can be decomposed in two parts, the first is about