The TDD road continued .... again

by Lord Cod3n 24. September 2008 12:10

Please feel free to leave me comments on items you think could use some elaboration.

So in my attempt to multi-task (learn mvc, learn TDD) at the same time I was going through the test cases in MVC preview 5.  I found these videos which are excellent TDD and MVC videos.  The first video of the series can be found here:

http://www.asp.net/learn/mvc-videos/video-405.aspx 

The Video series is called MVC Pair Programming.

 

The one of the gentlemen in the video is the developer of the NUnit Testing Framework.  Very awesome videos if you guys ever browse my blog.

 

Code Happy,

Bill

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

MVC and TDD

by Lord Cod3n 23. September 2008 01:53

Trying to better my understanding of the MVC framework from Microsoft   I begin stepping through the test cases.  This perspective is one of the reasons I love TDD it is a good way to figure out what the code is supposed to do.

 

I believe that some of the test cases are not valid.  Here is an example:

 

        [TestMethod]
        public void FindActionMethodDoesNotMatchProperty() {
            // FindActionMethod() shouldn't match special-named methods like property getters.
            // Arrange
            var controller = new FindMethodController();
            ControllerContext context = GetControllerContext(controller);
            ControllerActionInvokerHelper helper = new ControllerActionInvokerHelper(context);
            // Act
            MethodInfo mi = helper.PublicFindActionMethod("get_Property");
            // Assert
            Assert.IsNull(mi);
        }

This is an example of testing the framework.  When they do reflection to get the methods they do not ask for the properties. Is this a valid test ? 

Right now I am going to go with no.  It could be argued that they are making sure their code works as expected, but when you write code and ask for something specific i.e. (methods)  how would you get back a property?

 

Have a good day

Bill

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

TDD going deep Day 2

by Lord Cod3n 19. September 2008 06:29

 First of, created the following test case...

        [TestMethod]
        public void canGetListofClassesFromCodeFile()
        {
            CodeManager cm = new CodeManager();
            string[] classnames = cm.GetClassNamesFromFile();
            Assert.IsTrue(classnames.Count() > 0);
        }

What I did here was write the test the way I wanted it to work.  This is a little difficult because design and implementation keep flying around in my head.  I suppressed the urge to design and possibly over-design and went with adding a user story/functionality to the code. 

The first time the test would not compile, so I implemented the GetClassNamesFromFile() with no code in the method.  The code compiles but throws a NotImplementedException.  We will return a List<string> with one element.  

The test case passed, and I am returned a List<string> instead, with a classname that I added. Once again I am faced with an incorrect implementation and I wonder do I add another test to fix it, or do I modify the code now. 

Q. What happens when one test breaks another test?

A.  [I have not been able to answer this.  Feel free to post an answer in the comments] 

Now attempting, to implement reading in the code file.  My unit test is failing, so I am incrementally fixing it.

My code feels very messy at the moment.  I will post up more later.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

TDD Part 2

by Lord Cod3n 18. September 2008 14:53

After some feedback from Tony Rasa from http://www.elegantcode.com/ , I decided not to finish the book I started with.  If I have not mentioned it before, I use Safari Books Online from O'reilly.  This gives me instant access to over 2000 books from Microsoft, Apress, O'reilly, and others.    I switched to "Test Driven Development by Example" by Kent Black.  This book seems to be more inline with what I am looking for.  It answered some of my questions right up front.  

Warning:  The examples in the book are in JAVA, but it often reads similiar to C#, you should pick it up with no problem.  

Here is a piece I found interesting:

...following are two of the three strategies I know for quickly getting to green:
  •  
    • Fake It— Return a constant and gradually replace constants with variables until you have the real code.
    • Use Obvious Implementation— Type in the real implementation.
When I use TDD in practice, I commonly shift between these two modes of implementation. When everything is going smoothly and I know what to type, I put in Obvious Implementation after Obvious Implementation (running the tests each time to ensure that what's obvious to me is still obvious to the computer). As soon as I get an unexpected red bar, I back up, shift to faking implementations, and refactor to the right code. When my confidence returns, I go back to Obvious Implementations.
There is a third style of TDD, Triangulation, which we will demonstrate in Chapter 3. However, to review, we
  •  
    • Translated a design objection (side effects) into a test case that failed because of the objection
    • Got the code to compile quickly with a stub implementation
    • Made the test work by typing in what seemed to be the right code

The translation of a feeling (for example, disgust at side effects) into a test (for example, multiply the same Dollar twice) is a common theme ofTDD. The longer I do this, the better able I am to translate my aesthetic judgments into tests. When I can do this, my design discussions become much more interesting. First we can talk about whether the system should work like this or like that. Once we decide on the correct behavior, we can talk about the best way of achieving that behavior. We can speculate about truth and beauty all we want over beers, but while we are programming we can leave airy-fairy discussions behind and talk cases. 

 This presented a great example on how to think about tests.  I like all three of these ideas and will try to use them moving forward. 

 

Code Happy,

Bill 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

TDD Update

by Lord Cod3n 18. September 2008 10:14
Wow this gets complicated fast. I am still have trouble what kind of tests I should write. I am attempting to write a code Indexer with Search capabilities. Here is the list of Test Cases so far:
  • CodeManagerCanCreateInstanceOfFileManager
  • CodeManagerReturnsEmptyListWhenSearchTermNotProvided
  • CanGetAListOfFilesFromDirectory
  • CanGetListOfOnlyCodeFiles
  • CreateCodeFileObject

The main problem I have is trying to figure out how to move to the next test. The code is evolving and I feel confident after I make changes.  The code generation feels off.  I have created a Test List.  Some of the items I am currently researching include What goes in a Test Lest ?   Does it map to a Use Case?  Something the developer does?

Let me give an example of this one.  I am creating a test then I see a need for the FileManager object.  Do I then create a Test that makes me create the File Manager Object , or do I just create another test and implement the File Manager Class as a by product of that Test?

 Right now the Code has evolved to include the following objects :   (CodeFile,FileManager,CodeManager) using SoC(Separation of Concerns) I am attempting to isolate working with the File System.  The FileSystem object uses the System.IO namespace.  The CodeManager uses the FileManager to search the file system and Contains a List of CodeFiles.  

 

I am researching by reading the following book:

Test-Driven Development in Microsoft® .NET 

You can find it on amazon here

http://www.amazon.com/Test-Driven-Development-Microsoft-NET-Professional/dp/0735619484/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1221783997&sr=8-1  

 

 More updates when the mood hits.

Bill 

 

 

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

TDD diving deep

by Lord Cod3n 18. September 2008 04:26

I am taking the TDD plunge even more deeply.  I thought about a new product idea.  I think this one will be useful.  I am sitting here trying to figure out where to start.  What should the first test be?  Where should I begin ?  How big should the Test Case be ?   Does a Test Case map to a Use Case ? I am going to research this questions more deeply and post my finding up on my blog.  

 

Code Happy,

Bill 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

William Moore is the lead Software Architect and Technologist for Coden Enterprises. He has more than a decade of software development experience primarily Microsoft Platforms.  William enjoys the full gamit of coding everything from the UI down to the database.

Most comments

Page List