Daraja Framework unit test enhancements

The Daraja Framework unit tests (DUnit/FPCUnit based) are now more self-documenting. A new HTTPTestCase test base class provides methods CheckGETResponseEquals, CheckPOSTResponseEquals, CheckGETResponseContains, CheckGETResponse404, and others, which allow to write more concise unit test methods.
The changes are available in the master branch, a snapshot is available for download here.

Continue reading

Advertisements

NetBeans 7.0.1 Released

Aside

The NetBeans Team has released NetBeans IDE 7.0.1, with full support for the official release of the Java SE 7 platform. NetBeans is an open IDE for Java, C++, PHP and Groovy which includes tight integration of Java EE application servers, unit tests, revision control, build / CI tools, and recently announced 1,000,000 active users.

If you already have NetBeans IDE 7.0 installed, launch the IDE and an update notification will appear. Click the alert-box to install the updates.

Atlassian Raises $1 Million for Room to Read through Sales of Starter Licenses

Atlassian, a leader in software for accelerating product development and collaboration,  announced on March 2, 2011 the company will mark $1 million in donations to Room to Read, a global non-profit that seeks to transform the lives of millions of children in developing countries by focusing on literacy and gender equality in education. The company raised the funds with the help of their customers through the sale of $10 software licenses, one of the first broad-based cause-for-marketing (“causium”) programs.

Funds from the Atlassian donation have been used to establish libraries and schools in developing nations, publish local language literature, and fund holistic educational opportunities for girls who are at high-risk of dropping out of school.

Press release

How can I disable DUnit tests programmatically?

For integration tests of Habari ActiveMQ Client libraries, I created a DUnit test suite which runs once for every version of the message broker. Unfortunately, some of the tests always fail because of known bugs in the tested version of the message broker (not the client library).

This means the test suites will never complete with 100%. For automated tests however, I need a 100% success score, otherwise, continous integration tools will detect a failed build.

DUnit does not offer a ready-made method to disable tests in a test suite by name. So I wrote a procedure which takes a test suite and a list of test names, and then disables all tests with a matching name, and also performs a recursion into nested test suites.

Here is the code, feel free to use it:

procedure DisableTests(const ATest: ITest; const AExclude: TStrings);
var
  I: Integer;
begin
  if AExclude.IndexOf(ATest.Name) <> -1  then
  begin
    ATest.Enabled := False;
  end;
  for I := 0 to ATest.Tests.Count - 1 do
  begin
    DisableTests(ATest.Tests[I] as ITest, AExclude);
  end
end;

Example usage (the TStringlist ‘Excludes’ is created in the Setup method):

procedure TActiveMQ541Suite.SetUp;
begin
  // fill test suite
  inherited;

  // exclude some tests
  Excludes.Add('TestBytesMessages');
  Excludes.Add('TestBigMessages');
  DisableTests(Self, Excludes);

  LaunchActiveMQ('5.4.1');
end;

New Code Coverage Report Tool for Delphi

Delphi Code Coverage is a tool by Christer Fahlgrren which generates HTML reports for “line coverage” of Delphi applications. This project was inspired by great tools in the Java world such as Emma.

Download

The source code and binary is available online at http://code.google.com/p/delphi-code-coverage/

Output

For each unit there will be a unit.html with a summary of the coverage, followed by the source marked up. Green lines were covered. Red lines were not covered lines. The other lines didn’t have code generated for it. There is also a Coverage_summary.html file that summarizes the coverage and has links to the generated unit reports.

Hudson Support

Version 0.3 of the tool has been released and introduced Hudson support.

Read more: Delphi Code Coverage in Hudson

Why 1.99 suddenly no longer equals 1.99

A strange problem suddenly occurs in all my Delphi 7 and Delphi 2009 unit tests.

I used DUnit CheckEquals to compare two Currency values, like

  CheckEquals(1.99, SomeCurrencyValue)

This worked fine in the IDE and in our build scripts, which run using the same version of DUnit for two years. Now, all of a sudden, all tests fail with strange error messages like

Expected: <1.99> - Found: <1.99>

With some newsgroup help I found that something has changed a processor flag which is responsible for floating point operations. Digging deeper in my unit tests, I found the root cause in the IBX component TIBDatabase, which seems to modify this flag.

TIBDataBase.Create(nil) changes the value of Get8087CW from $1372 to $1272, a very strange value.

procedure TForm2.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add(Format('FPU CW = $%4.4X',[Get8087CW]));
  TIBDataBase.Create(nil);
  Memo1.Lines.Add(Format('FPU CW = $%4.4X',[Get8087CW]));
end;

Tested on two systems running Windows 2000 SP 4, InterBase 7.5.1 and 2007 libraries (gds32.dll), Delphi 7 and Delphi 2009

Delphi tool box: a starter kit

Tests

First things first: unit tests. Before you start to write a program, think about testing. Download DUnit if it is not already included in your version of Delphi. DUnit is Open Source. New versions of DUnit include automatic memory leak detection for all test cases, using FastMM4.

DUnit GUI test runner

There are also add ons available for DUnit, for example the OpenCTF component test framework. If you are new to the idea of unit testing and DUnit, you should read this article. The Wikipedia also contains information about Test Driven Development.

Speed

Now it’s time to “turbo charge” your IDE with DelphiSpeedUp, a free plugin for Delphi/BCB/BDS/CodeGear RAD Studio. It speeds up the time to load the IDE and it also improves the whole speed of the IDE. Note that it does not improve the speed of compiled applications – but you can skip to the section More Speed below if this issue is very urgent.

Comfort

Next in the list are the GExperts, an almost incredible set of tools built to increase the productivity of Delphi and C++Builder programmers by adding several features to the IDE. GExperts is Open Source and supports all editions of Delphi down to version 3. It offers a procedure list, grep search, to do lists, tab order and component replace wizards and many many more.

GExperts Grep results window

Another collection of useful IDE extensions, including a ‘uses list cleaner’, are the cnPack IDE Wizards (CnWizards), a Free Plug-in Tool Set for Delphi/C++ Builder. The list of wizards includes for example a “Uses Unit Cleaner” and “Source Codes Statistics”.

cnWizards

cnWizards GUI screenshot

Some IDE extensions are also included in the Jedi Code Library package. For example, they can add a favorite folders combo box to the Delphi Open File dialog.

Style

Waste no time to format your source code manually – use DelForExp, a freeware Pascal source code formatter for Delphi 2/3/4/5/6/7/9/2007 written by Egbert van Nes. At default, the style of the Borland source code is followed closely. For Delphi 2009, DelForExp is included in an experimental version of GExperts.

More Speed

Your Delphi applications need more speed? One of the first things you can do (besides checking the code for the usual performance bottlenecks), is to use a faster memory manager.  Newer versions of Delphi use FastMM4 by default, a lightning fast replacement memory manager for Borland Delphi Win32 applications. For older versions of Delphi, you can download it from SourceForge. FastMM4 is very easy to use and can also help to identify memory leaks.

Safety First

In the software development circus, source version control is your safety net. If you do not have a preferred version control system, try the open source version control system Subversion. A Windows Explorer integration for Subversion, TortoiseSVN, is also available. It includes many useful tools, including a diff and merge application.

TortoiseSVN context menu

Automatic Component Tests for Delphi VCL Applications

The OpenCTF component test framework helps to build automatic tests for all (visual and non-visual) VCL components in a Delphi application. It is based on the DUnit framework.

How does it work?

  • OpenCTF iterates over the Forms and DataModules and dynamically creates test cases for the components
  • Customized test classes detect which components have to be tested, and configure the test steps

Continue reading