Using DUnitX running under CI

Hi,

i want to execute a unit test running under Continua. The unit test is part of a group file (.groupproj). It gets compiled successfully. It also executes, but never stops.

I’d expect the Continua action to pass “-exit:continue”, but that does not happen obviously. There is no command line argument in the action either, that i could configure. Adding an option file is overkill.

Adding a define CI as suggested here is overkill too:
https://www.finalbuilder.com/resources/blogs/integrating-dunitx-unit-testing-with-continua-ci

I would need to restructure a running system, removing the unit test of the project file and instead add an explicit action with continua.

There must be something smarter, right?

Thomas

Can you show your dpr? Without seeing what you have it’s impossible to know exactly what is going on.

We don’t pass --exit - that is something we probably should do, I guess we just assume people would define CI when compiling the project. How are you compiling it, FinalBuilder or MSBuild?

Also what version of Delphi and DUnitX - are you using the DUnitX bundled with your delphi version or from github?

Hi Vincent,

i use Finalbuilder’s MSBuild action. I could not find an easy way to pass the “CI” define for it. Switching to the Delphi Build Action is not an option, as it requires a different approach for the entity of the script.

The system under test is compiled with Delphi 10.4.1 and DUnitX is provided by that Delphi installation.

The code is generated by DUnitX’s Wizard.

program MyTest;

{$IFNDEF TESTINSIGHT}
{$APPTYPE CONSOLE}
{$ENDIF}

{$STRONGLINKTYPES ON}

uses
  SysUtils,
  {$IFDEF TESTINSIGHT}
  TestInsight.DUnitX,
  {$ENDIF }
  DUnitX.Loggers.Console,
  DUnitX.Loggers.Xml.NUnit,
  DUnitX.TestFramework,
  MyUnits,,,,,;

var
  runner : ITestRunner;
  results : IRunResults;
  logger : ITestLogger;
  nunitLogger : ITestLogger;
begin
    ReportMemoryLeaksOnShutdown := True;
{$IFDEF TESTINSIGHT}
  TestInsight.DUnitX.RunRegisteredTests;
  exit;
{$ENDIF}
  try
    //Check command line options, will exit if invalid
    TDUnitX.CheckCommandLine;
    //Create the test runner
    runner := TDUnitX.CreateRunner;
    //Tell the runner to use RTTI to find Fixtures
    runner.UseRTTI := True;
    //tell the runner how we will log things
    //Log to the console window
    logger := TDUnitXConsoleLogger.Create(true);
    runner.AddLogger(logger);
    //Generate an NUnit compatible XML File
    nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
    runner.AddLogger(nunitLogger);
    runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;

    //Run tests
    results := runner.Execute;
    if not results.AllPassed then
      System.ExitCode := EXIT_ERRORS;

    {$IFNDEF CI}
    //We don't want this happening when running under CI.
    if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
    begin
      System.Write('Done.. press <Enter> key to quit.');
      System.Readln;
    end;
    {$ENDIF}
  except
    on E: Exception do
      System.Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Hi,

i’ve come up with a solution by introducing an include-file, that controls the compiler defines for the different environments. This way i can also configure TestInsight as a test runner for local development. The Unit-Test is now up and running. The results are integrated with Continua, which looks very nice.

Still, i suggest, that the Continua DUnitX action should pass the “exit” parameter. This should be no big deal and helps running unit tests out of the box.

Thomas

Hi Thomas

The next update to Continua CI will have the exit parameter (I saw a commit for it yesterday) .

As for adding compiler defines with MSBuild, you can add them via the DCC_Define property

Note the $$(DCC_Define) is so that we are adding to the defines in the project rather than replacing them - the double $ is to stop FB treating it as a variable that needs to be expanded.

Hi Vincent,

thanks a lot for your clarification. Knowing how to handle the MS Build action is of value.

Thomas