Helping Developers Master PowerBuilder Classic and .NET

Yakov Werde

Subscribe to Yakov Werde: eMailAlertsEmail Alerts
Get Yakov Werde via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: Enterprise Architecture, Microsoft Developer

Blog Post

What Are Assertions?

PowerBuilder Journal - The crux of "Test Driven Development" and refactoring is writing assertions to test your code

PBDJ Blog on Ulitzer

PowerBuilder Developer's Journal - The crux of Test Driven Development and refactoring is writing assertions to test your code.   So what's an assertion?  The dictionary says that an assertion is "a positive statement or declaration."  According to the computing dictionary (this is definition you're looking for) it's "An expression which, if false, indicates an error."  In unit testing you are formulating assertions to catch not supposed to happen coding errors.  So you write the assertion first in a test - then you write simple code in the method under test to make the test pass.  Then you write more complex code and test again and around you go etc. etc. until your logic is complete and the test still passes.  Now you have confidence that your method really works!

OK.  Now the catch <g>- What about when you want to write a test that is expecting an exception - Usually when an exception is thrown in code - that's a bad thing and you want to know about it.  Well following the definition for assertion you set up for an exceptional condition and then write an assertion that will make the exception occur.  So the error is when the assertion does not occur - So you leave the catch block empty - and in the TRY block, on the line after the real assert you add another assertion that this line will never occur - cause if it does then that's a bug cause the exception was never thrown!

Insight: I'd assert that 'Unit Testing and TDD is a hot topic in the industry.' Evidence - publishers are releasing new books on the topic.  They only publish if they can make $$ - so developers must be buying!

Observation:  TDD gives you more freedom to experiment.  Sometimes you identify little changes that might just improve the code - but you've used never the technique or written anything like it before.   Ordinarily because of the overhead of testing via debugging you would be inclined not to bother since the deadline is looming and time is tight and debugging can be a long drawn out affair - BUT - when you have a test in place and know you code is working - you can make that little experimental change and run the test in a few microseconds.  Wow

Funny:  Writing courseware is allot like TDD - You write Objectives (High Level Design) -  Then you write Quiz Questions  (Assertions!!!!).  Then you write the detail (Implement the method). Someone can test their understanding through doing the questions!  (iterate as necessary) Amazing!!

Qutable quote:"Yesterday's pie in the sky becomes today's desert".  I arrived at this one while thinking about how the object purist ideas of the late 90's early 2000's Test Driven Design and Refactoring have become the powerful necessary development methodologies in today's application world.

Off the wall observation: Did you ever notice that weird is a weird word - remember - I before E except after C - so it should be spelled wierd but it's not!

More Stories By Yakov Werde

Yakov Werde, a 25 year IT industry veteran, is a member of TeamSybase and the newly formed Sybase Customer Evangelist Team. Yakov is a recognized author, speaker and trainer who has been designing and delivering PowerBuilder, .NET, EaServer, Web App Development, and Java training for over 14 years to corporate, military and government developers. Prior to discovering his aptitude as an educator, Yakov worked as an architect, project manager and application coder in the trenches of application software development. Yakov holds a Masters in Education with a specialty in instructional design for online learning from Capella University and a BS in math and computer science from Florida International University. Yakov, managing partner of eLearnIT LLC (www.elearnitonline.com), authors and delivers workshops and web based eLearning tutorials to guide professional developers toward PowerBuilder Classic and .NET mastery. Follow Yakov on Twitter as @eLearnPB