The Artima Developer Community
Sponsored Link

Weblogs Forum
A Set of Unit Testing Rules

50 replies on 51 pages. Most recent reply: Jan 21, 2011 2:19 AM by Steve Merrick

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 50 replies on 51 pages [ « | 1 ... 30 31 32 33 34 35 36 37 38 ... 51  | » ]
James Tikalsky

Posts: 12
Nickname: jt2190
Registered: Dec, 2003

Re: A Set of Unit Testing Rules Posted: Sep 15, 2005 10:54 AM
Reply to this message Reply
Advertisement
> What if you are coding outside the ivory tower? Suppose
> you are working at Microsoft and your assignment is to fix
> a bug in CreateFile()
> (http://msdn.microsoft.com/library/default.asp?url=/library
> /en-us/fileio/fs/createfile.asp), whose declaration looks
> like this:
>
HANDLE CreateFile(
> LPCTSTR lpFileName,
> DWORD dwDesiredAccess,
> DWORD dwShareMode,
> LPSECURITY_ATTRIBUTES lpSecurityAttributes,
> DWORD dwCreationDisposition,
> DWORD dwFlagsAndAttributes,
> HANDLE hTemplateFile
> );

> First, you'd probably like to write some unit tests (well,
> I guess that would be impossible, since any test of
> this function would not be a "unit test" by the definition
> proposed here), to make sure you don't break the existing
> behavior.
>
> Refactoring to a lot of little functions is not an option
> here -- that would break thousands and thousands of
> applications.

If by "Refactoring to a lot of little functions" you're thinking that we'd change the method signature, then you're right. We'd be breaking the existing API, which is a no-no.

However, as developer/bug-fixer, what is to stop us from extracting the buggy piece of code inside of CreateFile() into it's own function or functions, that we could then unit test more easily? (And if the reason in this example is I/O performance, does that mean that this approach to refactoring/writing tests would NEVER work?)

Flat View: This topic has 50 replies on 51 pages [ « | 30  31  32  33  34  35  36  37  38 | » ]
Topic: Computer About to Play Jeopardy Previous Topic   Next Topic Topic: The Search for Requirements

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use