BYTE.com
RSS feed

Newsletter
Free E-mail Newsletter from BYTE.com
Email Address
First Name
Last Name




 
    
             
BYTE.com > Features > 2003

C# Features Useful for Testing

By Dr. Thomas Plum

October 13, 2003

(C# Features Useful for Testing :  Page 1 of 1 )



Nowadays, writing test suites is the main business of my company, Plum Hall. First came C, then C++, and then Java. The structure of the Java test suite is significantly different, because visibility of names should follow class inheritance, whereas the C and C++ suites used the global namespace rather freely. (Test code isn't always intended to follow the same guidelines as product code.)

Writing a test suite for C# was in various ways similar to writing a test suite for Java, but there are several interesting ways that C# provides useful features from its C/C++ heritage—features that permit more straightforward structuring of the testing.

In particular:

1. C# has a preprocessor; Java doesn't. But compared with the "anything-goes" preprocessor of C and C++, the C# preprocessor is very carefully restricted. It supports #define in the code or via command-line option, but requires that all defining be complete by the first line of real code. In other words, the entire file of real code must be compiled under exactly the same set of definitions. And the only thing you can do with those preprocessor definitions is #if-#elif-#else; but that's all that's really needed anyway.

For example, a test suite can skip cases if some language feature is not yet implemented. During the years of evolution of C++ and C99 we had to use "not-yet-implemented" workarounds in hundreds of code contexts:

#if LACKING_FEATURE_X
#define SKIP123A45
#endif
 ?
#if !SKIP123A45
    [positive test for case 123A45]
#else
    [print 123A45 skipped]
#endif

In this example, some particular test named "123A45" is being skipped if "feature X" is missing.

The C# preprocessor also has the #error feature; test suites can use this feature to implement the "not-yet-implemented" workaround in negative tests:

#if !SKIP123A46
    [negative test for case 123A46]
#else
    #error 123A46 skipped
#endif

2. C# has enums, and Java doesn't. But compared with C and C++, the C# enums require fully-qualified names, just like member names of classes.

 Page 1 of 1 


BYTE.com > Features > 2003
Dr. Dobb's Media Center
BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE: Volume 2 - Heuristic Algorithms
The Best of BYTE: Volume 2 - Heuristic Algorithms
In this volume of Best of BYTE, we explore the emergence of some heuristic algorithms. Although we have only scratched the surface of this intriguing subject, we hope we've suggested the potential of the synthesis of heuristics and algorithms.

© 2008 Think Services, Privacy Policy, Terms of Service, United Business Media Limited
Site comments: webmaster@byte.com
Web Sites: BYTE.com, dotnetjunkies.com, Dr. Dobb's Journal, SD Expo, Sys Admin, sqljunkies.com, Unixreview



MarketPlace
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version
Try Numara FootPrints 9, The ITSM software that Delivers Real Value, Flexibility and Results.
Sign Up & Get Full Access To The Definitive Online Book Collection With SkillSoft's Books24x7�.
Wanna see your ad here?
 

web2