How to convert DUnit Tests to DUnitX

From RAD Studio
Jump to: navigation, search

Go Up to DUnitX Overview


Conversion from DUnit to DUnitX is relatively simple. DUnit.DUnitCompatibility.pas has a TTestCase class with all the Check(X) methods on it. They are marked as deprecated, which delegates to the new Assert method.

To convert from DUnit code to DUnitX follow these steps:

  1. In the uses clause, replace
    TestFramework
    with
    DUnitX.TestFramework,DUnitX.DUnitCompatibility;
  2. Change the registration to
    TDUnitX.RegisterTestFixture(TYourTestClass)

Enabling Stack Trace Support

You can enable the stack trace support for DUnitX using your DUnit code. For that, DUnitX has a DUnitX.StackTrace.inc file. You have to uncomment the definition for the provider you want to use. If you want to provide your own stack trace provider, then implement IStacktraceProvider and register it with

TDUnitXIoC.DefaultContainer.RegisterType<IStackTraceProvider,TYourProvider>;

How does DUnitX differ from DUnit?

The terminology of DUnitX is different to DUnit. The following table shows the differences:

Feature DUnit DUnitX

Base Test Class

TTestCase

None

Test Method

Published

Published or decorated with [Test]

Fixture Setup Method

NA

Decorated with [SetupFixture] or constructor

Test Setup Method

Override Setup from base class

Decorated with [Setup]

Test TearDown Method

Override Teardown from base class

Decorated with [TearDown]

Namespaces

Through registration parameter (string)

Unit Names (periods delimit namespaces)

Data driven Tests

NA

Decorated with [TestCase(parameters)]

Asserts

Check(X)

Assert class

Asserts on Containers(IEnumerable<T>)

Manual

Assert.Contains, Assert.DoesNotContain, Assert.IsEmpty

Asserts using Regular Expressions

NA

Assert.IsMatch (XE2 or later)

Stack Trace support

Jcl

Jcl, madExcept 3, madExcept 4, Eurekalog 7

Memory Leak Checking

FastMM4

FastMM4 (under construction)

IoC Container

Use Spring or other

Simple IoC container Built in

Console Logging

Built in

Built in (quiet or verbose modes)

XML Logging

Built in (own format)

Built in - Outputs NUnit compatible xml

See Also