Jump to content
John R.

Delphi 12 messing up with test project's DPR when using TestInsight and DUnitX

Recommended Posts

I'm wondering if there is some workaround to this problem I frequently have. My test project's DPR looks like this:

 

program tests;

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

{$STRONGLINKTYPES ON}

uses
  System.SysUtils,
  {$IFDEF TESTINSIGHT}
  TestInsight.DUnitX,
  {$ELSE}
  DUnitX.Loggers.Console,
  DUnitX.Loggers.XML.NUnit,  // <-- This line is removed from time to time by Delphi IDE
  {$ENDIF }
  DUnitX.TestFramework,

  // [...]

 

But every time I add a new unit to that project and save it, the Delphi IDE decides to remove this line, and only this one: DUnitX.Loggers.XML.NUnit

 

Is that a known problem ? Is there some workaround ?

 

I'm using Delphi 12 Patch 1 with TestInsight 1.2.0.6

Share this post


Link to post

I guess that is caused by the {$ELSE} part of the TESTINSIGHT conditional. You can safely remove that:

  System.SysUtils,
  {$IFDEF TESTINSIGHT}
  TestInsight.DUnitX,
  {$ENDIF }
  DUnitX.Loggers.Console,
  DUnitX.Loggers.XML.NUnit,
  DUnitX.TestFramework,

 

  • Thanks 1

Share this post


Link to post
Posted (edited)

My general advice to this is usually to move any conditional unit usage to its own unit and then only reference that unit in the dpr. Unfortunately, that is not some practice the DUnitX Expert is using.

It would possibly also reduce the duplicated code generated for the dpr main every time.

Edited by Stefan Glienke
  • Thanks 1

Share this post


Link to post

There is no generic "works for everyone" main dpr setup for dunitx - the code depends on what logging and settings you want. You typically do not want the console logger or the xml logggers when using TestInsight - and when running on a CI server you probably don't want the console logger.

 

I guess we could move some of the generated code to another generated unit so the IDE doesn't mess with the ifdefs - I don't have time to work on it at the moment but happy to accept a PR that improves this situation.

 

 

  • Like 1

Share this post


Link to post
16 hours ago, Vincent Parrett said:

You typically do not want the console logger or the xml logggers when using TestInsight - and when running on a CI server you probably don't want the console logger.

The inclusion of the units seems to do no harm. The linker probably omits them when no instance is created.

 

It is different with TestInsight as unit TestInsight,DUnitX may not even exist.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×