The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘Unit Testing’ Category

A few must watch videos on test driven development and unit testing

Posted by jpluimers on 2014/09/25

If you are going to do test driven development and unit testing, you should watch these videos and slide decks, most of them by Miško Hevery:

  1. Not a video, but a good starter: Guide: Writing Testable Code (or read the PDF version).
  2. 0:32:07 ▶ “The Clean Code Talks — Unit Testing” – YouTube.
  3. 0:37:56 ▶ The Clean Code Talks – Don’t Look For Things! – YouTube. Read the rest of this entry »

Posted in .NET, Agile, C#, Delphi, Development, Java, Java Platform, JavaScript/ECMAScript, Pascal, Scripting, Software Development, Unit Testing, VB.NET | 2 Comments »

The Little Mocker (on Test Doubles; via: 8th Light)

Posted by jpluimers on 2014/08/21

Recently, I bumbped into the The Little Mocker | 8th Light by uncle Bob C. Martin.

It’s a nice conversation of a mocker, that explains about Test Doubles (with examples).

Mocks are a bit to Test Doubles like Stunt Doubles are to Body Doubles: a specific kind of Test Doubles.

The conversation step by step explains these Test Doubles probably based on Martin Fowler‘s list of Test Doubles or Mocks, Fakes, Stubs and Dummies at XUnitPatterns.com:

  • Test Dummy: returns nulls (or equivalents null) to consumers as they should not have used: the dummy is a filler in the parameter list to setup the System under Test.
  • Test Double: the generic term (sometimes informally called mocks, but they are not; see Test Mock below).
  • Test Stub: like a Test Dummy, but returns a specific value for a specific test (or group of tests). For instance return true for a LoginStub.
  • Test Spy: like a Test Dummy (or evenTest Stub) but also makes a note (or log) of each call (so you can spy on the calls). It can lead to coupling, so might make your tests fragile.
  • Test Mock: like a Test Spy, but allows verification of certain existence of absence notes or log entries (called Expectations). Like ensuring a certain call to theTest Mock was made with certain parameters.
  • Test Fake: unlike a Test Stub, as fakes have business-like behaviour (so it simulates business behaviour to a certain extent, for instance by having certain data-sets in memory, or responding with certain business logic for instance returning true for certain Login conditions). It also means thatTest Fakes need unit tests of their own.

The links in the above list all contain a small diagram showing the dataflow between the Test Double, System under Test, stc. Jeff Atwood has some nice graphics to go with them at Test Doubles: A Taxonomy of Pretend Objects.

In practice, Stubs and Spies are probably used most, followed by Mocks (either in code or with a Mocking tool).

Notes:

  1. The above order is how the story explains them, not the list by Martin Fowler or the list on WikiPedia.
  2. Want to know more on how to use Test Doubles? Read Test Double at XUnitPatterns.com and Mocks Aren’t Stubs or buy xUnit Test Patterns: Refactoring Test Code: Gerard Meszaros: 9780131495050: Amazon.com: Books.

–jeroen

Posted in Agile, Development, Software Development, Unit Testing | Leave a Comment »

Delphi types that cannot be used for TypeInfo

Posted by jpluimers on 2014/03/03

When writing the Spring4D unit tests for GetTypeSize to include as many TTypeKind values, I came across a few types that either did not compile, or were not supported by TypeInfo. I listed them below as I could not find them in the documentation.

I included a test named Test_EnsureAllTTypeKindsCoveredByCallsTo_Test_GetTypeSize_ that verifies that all TTypeKind values except tkUnknown are covered. So future extensions of TTypeKind will make the tests fail.

As a side issue, I really wanted to know if tkUnknown could be emitted by the compiler. It can sort of, for instance by defining discontiguous enumerations, but are incompatible with TypeInfo as well.

Types that do not compile at all: Read the rest of this entry »

Posted in Agile, Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Development, DUnit, Software Development, Unit Testing | 2 Comments »

Extreme Programming, a Reflection (via: 8th Light)

Posted by jpluimers on 2013/12/29

Thanks Uncle Bob Martin for posting this.

I’ve been trying (with increasing success: it takes time to get this all right) to practice XP (through various name changes) as much and wide as possible since almost 14 years, and only the last few years it is starting to be common practice for many more people.

take a moment to reflect back on 1999. A time when Kent Beck wrote a ground-breaking book. A book that changed everything. Look back and remember: Extreme Programming; and recognize it as the core of what we, today, simply think of as:

Good Software Practice.

–jeroen

via: Extreme Programming, a Reflection | 8th Light.

Posted in .NET, Agile, Continuous Integration, Delphi, Design Patterns, Development, Software Development, Source Code Management, Technical Debt, Testing, Unit Testing | Leave a Comment »

Cyber-Dojo: practice unit-tested programming in pairs/groups using Katas

Posted by jpluimers on 2013/11/07

Wow, I’ve been living under a stone (:

Just discovered the online Cyber-Dojo by Jon Jagger. It is an online manifestation of a Coding Dojo. Both have been there for years, and I think both are brilliant.

They take the concept of a Dojo as being a place to practice sports like martial arts in a pair or group setting with a series of Katas or practices.

Katas in a Dojo are a means for performing deliberate practice in order to learn new things. For instance, acquire new movement techniques, learn about your balance, gain strength, all in both a physical and mental way.

The aim of both is do more deliberate practice.

When performing Coding and Cyber Dojo, you should use Test Driven Development using pair programming and BabySteps. Those help you to slow down, as one of the Dojo Principles is for Katas to slow down. It reminds me of the “if you are in a hurry, sit down” mantra and is a key part of the Coding/Cyber Dojo Principles too.

The aim is to learn, and part of that is to first un-learn and open you to new thoughts. That’s why it is so cool that the Cyber-Dojo provides you with:

  • a bunch of pre configured programming languages*,
  • preformulated practices** (including a few cyber-dojo refactorings),
  • a small boilter plate to get started.

You’d think they speed you up, but that is not their aim. Like a regular Dojo it gives you an pre-set environment and gives you piece of mind to get started.

The Cyber Dojo does without a Sensei, whose purpose in a Coding Dojo is to ask questions in order to guide the participants.

That’s why it is good to use the Cyber Dojo as part of a Coding Dojo: basically the Cyber Dojo provides a standardizes set of tools to quickly setup a Coding Dojo.

Cyber Dojo languages

(a prime number, so the table is a bit distorted)

C Go PHP
C# Haskell Perl
C++ Java-Approval Python
Clojure Java-Cucumber Ruby
CoffeeScript Java-JUnit Ruby-Rspec
Erlang Javascript

Cyber Dojo practices

Many of the practices come from rosettacode.org.

100 doors Harry Potter Print Diamond
Anagrams LCD Digits Recently Used List
Bowling Game Leap Years Reversi
Calc Stats Mine Field Roman Numerals
Count Coins Monty Hall Tennis
Diversion Number Names Unsplice
Fizz Buzz Phone Numbers Verbal
Game of Life Poker Hands Yahtzee
Gray Code Prime Factors Zeckendorf Number

–jeroen

via:

Posted in .NET, Agile, C, C#, C++, Development, Java, JavaScript/ECMAScript, Perl, PHP, Scripting, Software Development, Unit Testing | 3 Comments »

.NET/C# duh moment of the day: “A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal (not the other way around; implicit != implicit)”

Posted by jpluimers on 2012/11/20

A while ago I had a “duh” moment while calling a method that had many overloads, and one of the overloads was using int, not the char I’d expect.

The result was that a default value for that char was used, and my parameter was interpreted as a (very small) buffer size. I only found out something went wrong when writing unit tests around my code.

The culprit is this C# char feature (other implicit type conversions nicely summarized by Muhammad Javed):

A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type.

Switching between various development environments, I totally forgot this is the case in languages based on C and Java ancestry. But not in VB and Delphi ancestry  (C/C++ do numeric promotions of char to int and Java widens 2-byte char to 4-byte int; Delphi and VB.net don’t).

I’m not the only one who was confused, so Eric Lippert wrote a nice blog post on it in 2009: Why does char convert implicitly to ushort but not vice versa? – Fabulous Adventures In Coding – Site Home – MSDN Blogs.

Basically, it is the C ancestry: a char is an integral type always known to contain an integer value representing a Unicode character. The opposite is not true: an integer type is not always representing a Unicode character.

Lesson learned: if you have a large number of overloads (either writing them or using them) watch for mixing char and int parameters.

Note that overload resolution can be diffucult enough (C# 3 had breaking changes and C# 4 had breaking changes too, and those are only for C#), so don’t make it more difficult than it should be (:

Below a few examples in C# and VB and their IL disassemblies to illustrate their differnces based on asterisk (*) and space ( ) that also show that not all implicits are created equal: Decimal is done at run-time, the rest at compile time.

Note that the order of the methods is alphabetic, but the calls are in order of the type and size of the numeric types (integral types, then floating point types, then decimal).

A few interesting observations:

  • The C# compiler implicitly converts char with all calls except for decimal, where an implicit conversion at run time is used:
    L_004c: call valuetype [mscorlib]System.Decimal [mscorlib]System.Decimal::op_Implicit(char)
    L_0051: call void CharIntCompatibilityCSharp.Program::writeLineDecimal(valuetype [mscorlib]System.Decimal)
  • Same for implicit conversion of byte to the other types, though here the C# and VB.NET compilers generate slightly different code for run-time conversion.
    C# uses an implicit conversion:
    L_00af: ldloc.1
    L_00b0: call valuetype [mscorlib]System.Decimal [mscorlib]System.Decimal::op_Implicit(uint8)
    L_00b5: call void CharIntCompatibilityCSharp.Program::writeLineDecimal(valuetype [mscorlib]System.Decimal)
    VB.NET calls a constructor:
    L_006e: ldloc.1
    L_006f: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
    L_0075: call void CharIntCompatibilityVB.Program::writeLineDecimal(valuetype [mscorlib]System.Decimal)

Here is the example code: Read the rest of this entry »

Posted in .NET, Agile, Algorithms, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, Encoding, Floating point handling, Java, Software Development, Unicode, Unit Testing, VB.NET | 1 Comment »

Frank Borland is back, but what does that mean?

Posted by jpluimers on 2012/09/23

Frank Borland is back. You can meet him at Micro Focus now – they acquired Borland a while ago – where he relates to things from the past:

Frank Borland first appeared in advertisements and on the cover of the SideKick manual in 1984. Later on, Frank appeared in the first version of the Turbo Tutor manual.

He is talking about powerful and affordable, has Facebook as well as presence on LinkedInTwitter and Google+.
But I when I look at the MicroFocus product portfolio, I don’t see any that are both affordable and powerful.

Todays software days are different than 30 years ago, but I do agree with a couple of the points he made:

  • Keep it open
  • Don’t make it big, make it better
  • Focus on the user experience
  • Listen to the community

I don’t think you necessarily need to meet these two though:

  • Meet every platform need
  • Make it affordable

As those two tend to contradict each other.

What do you think?

–jeroen

via: » Frank’s Story Meet Frank Borland.

Posted in Agile, Delphi, Development, Opinions, Software Development, Testing, Unit Testing | Tagged: , , , , , , , , , , | 21 Comments »

Delphi: Use TStrings to parse non-standard separated strings, and validate it with DUnit tests

Posted by jpluimers on 2010/09/08

Recently, I was at a client where in a project strings had to be split from:

'FI-150 1U; FI-049-I L=20 MM;LET OP LASVORM'

Into:

  • 'FI-150 1U'
  • 'FI-049-I L=20 MM'
  • 'LET OP LASVORM'

At first sight, this looks simple: Semicolon Separated Values and you are done.
Not so fast Mr Smart Alec: watch the optional spaces!

The best thing for problems like these is to start with an empty implementation that some units tests covering it.
I use DUnit for Delphi unit testing.

Unit testing should go with code coverage, but there are few Delphi code coverage articles.
I’ll get into code coverage later on, as I’m working with two of the code coverage people to get this to work nicely with Delphi 2010.

Mock objects can be a good addition to unit testing too, so in a future article, I will cover using mock objects with Delphi.

Read the rest of this entry »

Posted in Agile, Conference Topics, Conferences, Delphi, Development, DUnit, Event, Software Development, Unit Testing | 8 Comments »