Keyboard Shortcuts
Likes
- Testdrivendevelopment
- Messages
Search
Re: [TDD] How to use TDD to test a process?
Here is the a list of possible tests for the UserService.Record method: ? ?? Record__UserWithSameNameAlreadyExists__DeleteTheUser ???????????????????????????????????????????????? // Asserts only on calling the method _userDao.Delete with appropriate arguments ¨C you have to use a mock to do this ?? Record__ UserWithSameNameAlreadyExists _DeleteFailed__ReturnsFalse ?????????????????????? // Asserts on the method Record returning false ¨C you have to use a stub here to ensure that Delete returns false ?? Record__ UserWithSameNameAlreadyExists__SavesNewUserDetails?????????????????????????????????? // Asserts only on calling the method _userDao.Save with appropriate arguments (the passed user in this case) ¨C again a mock is needed ?? Record__ UserWithSameNameAlreadyExists_SavingFailed__ReturnsFalse????????? ??????????????? // Asserts again that the method Record should return false ¨C a stub for the method Save to return false ? (The test names are written using the notation ____) ? Pl. note that this is the minimum no. of tests that the method Record can have (given its cyclomatic complexity - 4) There may be other cases, which evolve depending on the data complexity, which gives more dimensions to the above tests. For ex. there may be null data, which is probably expected/not expected to be handled by the method. ? It is also but usual to be tempted to assert on more than one expected result in a single test, but the best practices prescribe not to do so, as it may be not be clear - which expectation failed. ? One way to check if you have enough tests is to see, if the list of tests are giving you the functional specification of the method under test. It is more efficient and useful technique in a test first approach, where the unit test spec could be checked before coding. Also, it may be possible to sort out glitches like, whether the userDao is actually expected user name or id. ? Best Regards, Surya On Tue, Apr 26, 2016 at 10:11 AM sailor.gao@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] How to use TDD to test a process?
Thanks for the reply.
Yes, actually I don't want to know the side effect. I just want to test the logic. I had planned to use stub or mock. But there are several branches. I thought it is a little duplicated. Because if gotten good code coverage, in every case I have to write the stub or mock for methods called. Could you give me some advice? Thank you. |
Re: [TDD] How to use TDD to test a process?
Donaldson, John
Sailor.gao, your question is not very clear.
I suppose you want to know if method Record actually calls GetUser then Delete or Save? So, either you reason by the side effects (such as the record has gone from the database), or you use a mock of some kind to show you call the expected methods in the expected order. John D. From: testdrivendevelopment@... [mailto:testdrivendevelopment@...] Sent: 25 April 2016 14:37 To: testdrivendevelopment@... Subject: [TDD] How to use TDD to test a process? I try to use stub but it seems not very good. I want to know how should I write the test case, and how many should it be? Could someone help me? Thank U! logic like this: public class User { public int ID { get;set; } public String Name { get;set; } public String BrokerID { get;set; } public String Timestamp { get;set; } } public interface IUserDao { User GetUser(string userID,string brokerID); bool Save(User user); bool Delete(User user); } public UserService { private IUserDao _userDao; public UserService(IUserDao userDao) { _userDao=userDao; } public bool Record(User user) { User origin=_userDao.GetUser(user.Name,user.BrokerID); if(orign) { if(!_userDao.Delete(origin)) { return false; } } if(!_userDao.Save(user)) { return false; } ; return true; } } |
How to use TDD to test a process?
I try to use stub but it seems not very good. I want to know how should I write the test case, and how many should it be? Could someone help me? Thank U! logic like this: public class User { ??? public int ID ??? { ??????? get;set; ??? } ??? public String Name ??? { ???????? get;set; ??? } ??? public String BrokerID ??? { ???????? get;set; ??? } ??? public String Timestamp ??? { ???????? get;set; ??? } } public interface IUserDao { ??? User GetUser(string userID,string brokerID); ??? bool Save(User user); ??? bool Delete(User user); } public UserService { ??? private? IUserDao _userDao; ??? public UserService(IUserDao userDao) ??? { ????????? _userDao=userDao; ??? } ??? ?? public bool Record(User user) ?? { ???????? User origin=_userDao.GetUser(user.Name,user.BrokerID); ???????? if(orign) ???????? { ??????????? if(!_userDao.Delete(origin)) ??????????? { ?????????????????? return false; ???????????? } ???????? } ???????? if(!_userDao.Save(user)) ???????? { ????????????????? return false; ? ? ? ?? return true;? ?? } } |
Re: [TDD] TDD Database migration code
A tool as Liquibase () would not help?? >>*The short version is: ?>>1. A command which generates a .sql file with a timestamp in the file name. In liquibase you create de .sql files. >> ?2. A?command which checks all the files in a folder,?and then does some comparisons to another db, and picks one or more .sql files to run on the db in question. I think that is exactly what liquibase does. On Wed, Apr 20, 2016 at 9:01 AM, Avi Kessner akessner@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
--
Abra?os,
´³´Ç²õ³Ü¨¦ |
Re: [TDD] TDD Database migration code
Ironically, after attempting to install pgTap and get it talking with python instead of perl, I ended up removing all the tests and DB specific code. Mainly because of what you were advising just now. The custom use cases were making my tests too brittle, so I found a better way to abstract it out. It will be good later on though if we have more complicated db functions, though hopefully I'll be able to persuade the team to avoid that. brought to you by the letters A, V, and I and the number 47 On Wed, Apr 20, 2016 at 2:17 PM, Adam Sroka adam.sroka@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] TDD Database migration code
You are welcome! General advice: be cautious about building functionality into the database. The database should be optimized for storage and retrieval. Decisions about how to ask the right questions of the database should probably be in a layer closer to the customer, and in the language appropriate to that place.? On Wed, Apr 20, 2016 at 1:06 AM, Avi Kessner akessner@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] TDD Database migration code
PgTap looks perfect. Thanks! On Apr 20, 2016 10:59 AM, "Avi Kessner" <akessner@...> wrote:
|
Re: [TDD] TDD Database migration code
Ideally I'm looking for something that creates databases, runs sql, is able to check the state of the database, and then destroys the database. I don't really care at what level that happens at. (Though easier is obviously better) ?.. (investigating pgtap now, thanks) brought to you by the letters A, V, and I and the number 47 On Wed, Apr 20, 2016 at 10:21 AM, Adam Sroka adam.sroka@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] TDD Database migration code
Are you talking about test driving database access code from a general purpose language? Or are you talking about test driving stuff inside the database engine? There is??but I would look for a way to do it at a higher level, unless... a gun was pointed at my head.?
toggle quoted message
Show quoted text
On Tuesday, April 19, 2016, akessner@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
TDD Database migration code
My google searches are giving me bad results... :( ? |
Re: [TDD] Behavioral challenges in adopting TDD
¿ªÔÆÌåÓýAbsolutely. I did this in one organization, starting with two unit tests. By the end of the week I had figured out how to add six more, and kept adding on. My work group picked up on what I was doing, and before long, the rest of the organization noticed that we had by far the best record in avoiding breaking the baseline of any group. They came over to learn. ?Within a year most of the organization was doing it as well.?We do TDD because it gives us clearly better results. As long as your co-workers can see you attaining those results, whether it is in higher productivity or better quality, they will be faced with a choice: either you are smarter than they, or you have found a technique that works, and which they can learn. Guess which they would prefer to believe? - Russ
----------------- Author,?Getting Started with Apache Maven <> Author, HttpUnit <> and SimpleStub <> Come read my webnovel,?Take a Lemon?<>,? and listen to the Misfile radio play <>! |
Re: [TDD] Node.js / javascript TDD Tutorials
Look at?. I think it is really good br JM 2016-04-13 19:51 GMT+02:00 Adam Sroka adam.sroka@... [testdrivendevelopment] <testdrivendevelopment@...>:
|
Re: [TDD] Node.js / javascript TDD Tutorials
TDD in Node.js is not substantially different than TDD in any other language. There are a dizzying array of frameworks to choose from. I have a strong preference for Jasmine as the test framework, particularly in CoffeeScript.?
toggle quoted message
Show quoted text
If you add the browser to the mix things get complicated, particularly if you are trying to test in the browser or test code you expect to manipulate the DOM in specific ways. But, server side is exactly the same as any other language, and any old TDD book/tutorial will put you in the right direction.? On Wednesday, April 13, 2016, reuven.yagel@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] Node.js / javascript TDD Tutorials
On Wed, Apr 13, 2016 at 3:37 PM, reuven.yagel@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] Behavioral challenges in adopting TDD
¿ªÔÆÌåÓýHi there, A short answer: Patience, love, and understanding, fostered by someone who's been there/done that. Do you have any TDD-experienced folks in the team who can work with your senior dev? A primary goal when I start pairing with devs is help them out with their current challenges, by showing them useful legacy code techniques to start getting their code under control and by helping them figure out other problems and coming up with better solutions (the primary goal of pairing). Sitting with them allows me to start working in test-first as we go along, talking about techniques, values, etc. as we go. This is effective for most devs, including senior ones. (I had one lead dev tell me "I've learned more in the past two weeks than in the past two years.") The legacy themes and techniques quickly demonstrate how it's possible to make changes and minimize fear. As far as the dip in productivity, it's not hard to get someone to agree that it makes logical sense and is worth the initial dip in productivity. On one simple score, most shops don't quantify a cost to develop a given feature, since they don't take into the account the cost of rework, the additional cost to understand poor code, and the true costs of defects. Regards, Jeff Langr Software Solutions, Inc. Pragmatic Unit Testing in Java?() Modern C++ Programming with TDD () Agile in a Flash ( Agile Java: Crafting Code with Test-Driven Development?() Essential Java Style ()
|
Re: [TDD] Behavioral challenges in adopting TDD
This may not seem like a real answer. Save it and come back after all else fails. Forget about all that stuff and start doing TDD. Do it by yourself. Do it with a partner if you can. Stop trying to make anybody else do anything. You seem to be describing a situation in which neither the docs nor the manager want to use TDD, so focus on what you can control. Maybe in six months someone will ask you about what you are doing that makes your code so good. Charlie On Apr 13, 2016 7:53 AM, "poojawandile@... [testdrivendevelopment]" <testdrivendevelopment@...> wrote:
|
Behavioral challenges in adopting TDD
HI, I am anticipating following challenges in TDD adoption. Any suggestion how to deal with such situations? The list is long :-). Thanks,?
W An |