Keyboard Shortcuts
Likes
- Testdrivendevelopment
- Messages
Search
Getting back into C# testing
I've been away from serious OOP programming for a while, working in Prolog, etc. ?So now I'm back, using VS2013, and starting development with a large CAD API. ? My TDD experience has followed
the old data-oriented style, testing whether a function causes the right kinds of objects to be produced, rather than testing that it invokes the right methods. ?(It makes more sense to me, that my concern is to construct the correct and very visible model, and not how that model was constructed.) So now, given this brand-new API (which I know is well made and stable), is it a good idea to create my own classes to
wrap access to the API, or is it better just to access the API directly? Following the TDD mantra of test-first, I'm thinking about: { ? setup the test scenario. ? do something interesting. ? check what happened. } I write the above in natural fashion, and then build classes and methods to match that fashion, and link those to the underlying API. Does
this all make sense? ?Shall I use the built-in test framework? ?Are there any valued innovations in the last years about software development? ? Alan Baljeu |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Starting with acceptance tests is a great idea. So is starting with high level unit tests, mocking the details, and then working your way down. Also, sometimes if I think I know what the essence of the problem is I will start there, or if I'm not even sure how I am going to do it I may just pick something to spike.?
Any of these techniques, or a combination, can be used with a given story. TMTOWTDI On Thursday, August 28, 2014, George Dinwiddie lists@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Michal,
On 8/28/14 12:03 PM, Michal Svoboda pht@... [testdrivendevelopment] wrote: Kaleb Pederson kaleb.pederson@... [testdrivendevelopment] wrote:I write acceptance tests all at once. I write unit tests a bit at a time, often starting with the creation of a new object whose definition does not yet exist. In this fashion I work inside-out within the bounds of outside-in.When the entire test is written up front (for a new class at least)Hi Kaleb, Even if the test is written in a bigger chunk, you can still add in theWith effort, you can. But how does that drive the design? - George -- ---------------------------------------------------------------------- * George Dinwiddie * Software Development Consultant and Coach ---------------------------------------------------------------------- |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Kaleb Pederson kaleb.pederson@... [testdrivendevelopment] wrote:
When the entire test is written up front (for a new class at least)Hi Kaleb, I hear what you are saying. But it really goes down to that gut feeling. Sometimes I want to see the whole story first, not just "once upon a time there was an object". It usually depends on what level of certainty I feel over my requirements. The objective is to drive the design with the test, not to just write it first. Even if the test is written in a bigger chunk, you can still add in the code one bit at a time and see the test fail for various reasons until you get (and subsequently fix) the desired one. Cheers, Michal |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
On Thu, Aug 28, 2014 at 8:53 AM, Colin Vipurs zodiaczx6@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
Please do. Feel free to e-mail me or post a link to the writeup once it's done :). --Kaleb |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
On Thu, Aug 28, 2014 at 8:38 AM, 'Donaldson, John' john.m.donaldson@... [testdrivendevelopment] <testdrivendevelopment@...> wrote: If you insist (as an earlier poster did) that you first write an assert, then you would avoid this ¡°compilation only¡± worry (as long as your assert is non-trivial). I remember seeing that post but I forgot to respond -- that's a good idea that I've never tried. Done properly that should provide the necessary guarantees. Thanks for re-pointing that out. --Kaleb |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Hi Kaleb, As others have said: Change gear depending on your experience wit TDD and comfort in the situation. There's a another point to be made though. Ron and Chet emphasized in their CSD training that TDD has two 'modes': design and implementation. When you write a new test, it usually introduces some sort of new concept in the system. You can write more than one line, even if the first line doesn't compile, if that helps you see what the interface/design should look like. When you have something you like, you make sure it compiles, but fails. Then you start with the implementation mode, and make it work.
If there are more than one or two new concepts introduced in one test, I'd wonder if the test is maybe a little to broad in scope, and I should take a smaller steps. Wouter
On Tue, Aug 26, 2014 at 5:48 PM, Kaleb Pederson kaleb.pederson@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
--
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Perhaps I should write this up somewhere. ?The usual example I give when teaching is using Java and moving a method from a static call no a non-static call. ?The test suite now needs to be updated in multiple places, hence the duplication.
I get you now. ?In my head I see this as two forms of failure, compilation failure and runtime failure. ?I won't even run the test if the compiler is complaining*. ?The key here really is to always see the test fail /for the right reason/, i.e. the diagnostic output of my assert. ?It's good practise to ensure your diagnostics messages convey all the information you want them to at this point anyway.
* At least in a language/IDE that offers good support? |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Donaldson, John
¿ªÔÆÌåÓýKaleb, ? If you insist (as an earlier poster did) that you first write an assert, then you would avoid this ¡°compilation only¡± worry (as long as your assert is non-trivial). ? John D. ? From: testdrivendevelopment@... [mailto:testdrivendevelopment@...]
Sent: 28 August 2014 16:27 To: testdrivendevelopment@... Subject: Re: [TDD] Three Law of TDD - to strictly follow, or not? ?
? On Tue, Aug 26, 2014 at 12:33 PM, Michal Svoboda pht@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
? --Kaleb
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
On Wed, Aug 27, 2014 at 8:23 AM, Colin Vipurs zodiaczx6@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
I had never thought about calling a single method on the SUT multiple times as duplication. I'll have to spend some more time thinking about that. ?
I responded to another of your e-mails a little bit ago that I think explains better, but I'll describe it again here. If the entire test is written up front, and a new class is under development, that test will fail because of a failure to compile. The author could in theory, write lots of production code and then see the test "pass" without ever having seen it fail for the expected reasons. I would hope that wouldn't happen, but not having seen the full development progress or the progression taken it's a concern that I have.
--Kaleb |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
On Tue, Aug 26, 2014 at 12:33 PM, Michal Svoboda pht@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
I think you've just described my biggest concern with writing the entire test up front. When the entire test is written up front (for a new class at least) the test will fail, because a failure to compile is considered a failure. The problem that I have with the approach is that when it "passes", does it pass for the right reason? Or, do we have unnecessary test code? or production code? Did the test ever fail for the expected reason, or did it fail only in the form of a compilation failure? --Kaleb |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Thanks for the feedback Jeff. In thinking about "green" tests and the process taken with TDD, I think it boils down to the fact that the name of the test should represent the goal for the test. Along the way the test will be green: it'll be green when you've just introduced a class and the test compiles for the first time; it'll be green when you've introduced the second test and still have duplication to extract out. It'll be green many times along the way but until the purpose of the test is met, i.e., until the test matches its description fully, it is incomplete... and that's alright.
--Kaleb
On Tue, Aug 26, 2014 at 11:31 AM, Jeff Langr jeff@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Answers inline.
Again I would put that down to duplication. ?It's extreme, but if I call a method from 15 tests I see that as something that should be extracted.
I'm not sure I'm following you here. ?Doesn't the failing test diagnostics provide this information/guarantee?
I think both of these come down to how big your tests are and how much functionality they're attempting to test in a single go. ?To draw an example, imagine I have a class that converts object A into object B - i will have 1 test for each and every field and incrementally add the conversion as I go.
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
I would always do this when leaving for the day, mostly as a way of reminding myself in the morning what I was working on On Wed, Aug 27, 2014 at 2:48 PM, Charlie Poole charliepoole@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
--
Maybe she awoke to see the roommate's boyfriend swinging from the chandelier wearing a boar's head. Something which you, I, and everyone else would call "Tuesday", of course. |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
A rule of thumb I followed for many years was to leave a failing test when taking a break. Charlie On Aug 27, 2014 6:41 AM, "Tim Ottinger tottinge@... [testdrivendevelopment]" <testdrivendevelopment@...> wrote:
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Never trust a test you have never seen fall. Tests can pass for the wrong reasons. You have to trust then or get rid of them. That said, there are intermediate steps which are legitimately green on your way to completing a more significant goal. That only leaves a few little procedural questions. How long does it remain incomplete? How do you denote that it is incomplete? How do you website you don't abandon it? Most of the time you work one test to completion before check-in or taking a break so it is a non-issue. But if you are forced to leave our for a while, these things matter. On Aug 27, 2014 3:09 AM, "Samuel ?slund samuel@... [testdrivendevelopment]" <testdrivendevelopment@...> wrote:
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Donaldson, John
¿ªÔÆÌåÓýI think all the answers have been wise and sensible. But then, I think the answers all come from ¡°Ha¡± or ¡°Ri¡± practitioners, and I suspect Kaleb was talking to ¡°Shu¡± people. (If you are wondering what I am talking about, there¡¯s a concise explanation of ¡°ShuHaRi¡± here: ) ? I¡¯d really like a beginner to try to stick to three rules pretty strictly, with the probably addition of Samuel¡¯s ¡°Commit¡±. ? John D. ? From: testdrivendevelopment@... [mailto:testdrivendevelopment@...]
Sent: 27 August 2014 14:55 To: testdrivendevelopment@... Subject: Re: [TDD] Three Law of TDD - to strictly follow, or not? ?
Exactly. You should only commit the test after you've gone through the full Red-Green-Refactor. In fact, assuming you're using DVCS or your own branch, I would go so far as to say that you should always Red-Green-Refactor-Commit. I've written more on this here: ? ? On Wed, Aug 27, 2014 at 4:09 AM, Samuel ?slund samuel@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
|
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Exactly. You should only commit the test after you've gone through the full Red-Green-Refactor. In fact, assuming you're using DVCS or your own branch, I would go so far as to say that you should always Red-Green-Refactor-Commit. I've written more on this here:
On Wed, Aug 27, 2014 at 4:09 AM, Samuel ?slund samuel@... [testdrivendevelopment] <testdrivendevelopment@...> wrote:
--
Steve Smith |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
¿ªÔÆÌåÓýOn 14/8/26 17:48, Kaleb Pederson
kaleb.pederson@... [testdrivendevelopment] wrote:
? You might want to consider the difference between a test during development locally and a test that have been checked in to the common repository. I have been confused by tests with names saying they check something that is not checked, making me spend time searching for problem in the wrong place. On the other hand during TDD it is rather important to know that the test actually fails, like you and others describe. The key as I see it is if the test is committed or not. Mostly the tests confusing me have come from being interupted while they happened to be green and then missing that they was not compete when coming back. Regards, //Samuel |
Re: [TDD] Three Law of TDD - to strictly follow, or not?
Kaleb Pederson kaleb.pederson@... [testdrivendevelopment] wrote:
Do you strictly follow the three laws of TDD as literally written?Either approach you described can be justified. Test that just contains one variable is actually complete and says "the object can be constructed this way". Remember there is an implied "this does not fail" even if there are no asserts. In the classic cycle, you would then proceed to write another test, that tells a different story. Then, in the refactor phase, you'd maybe remove the first test. From my experience indeed sometimes you want to go so slow that this is useful. Other times not. In absence of gut feeling, do baby steps. Also, in non-strict typed languages (i.e. javascript) a test that just describes object construction syntax could be useful. Do you consider, "an incomplete but green test is at best misleadingA test is only wrong in case you have never seen it fail. All other tests are complete and functional. As for misleading, that depends how good a story the test tells. Tests can lie or drift apart from reality. Usually that is more likely when the test uses mocks. Michal |