Jump to content
Registration disabled at the moment Read more... ×
Dave Novo

TestInsight Question

Recommended Posts

I am trying to create a "universal" Dproj file to use with DunitX, Delphi 12.3 and TestInsight 1.2.0.8.

 

What I want to achieve is as follows:

When I open the project the first time and open the TestInsight window in the IDE, the TestInsight window automatically populates with available tests. Not sure if that is even possible, or if I have to compile/run the program once. If so, that is an issue, my tests take about 2 minutes to run completely, and I am loath to have to wait 2 minutes to run all the tests just so they can be registered with the testInsight window. The workaround I have found is to find my shortest test and hit Alt+F9. Then all the tests get registered. But are the test names from the previous run not stored in some config file or something so that the IDE window can be refreshed (even if out of date potentially) when the TestInsight window first opens?

 

The other issue is that the IsTestInsightRunning code below always returns True. Even if I reboot the machine, start Delphi and compile my project with the TestInsight IDE window closed, it still returns true and starts running the registered tests.  I can see the testInsight window in the IDE briefly flash open with my one test selected (because RunRegisteredTests is executed), it runs that single test, and then closes.  Is there a way to figure out whether or not the TestInsight window is open in the IDE?

 

below is the code in my project file

 

program TestingProj;

{$IFDEF TESTINSIGHT}
{$UNDEF UseConsole}
{$ENDIF}

{$IFDEF UseConsole}
{$APPTYPE CONSOLE}
{$ENDIF}

{$STRONGLINKTYPES ON}
uses
  System.SysUtils,
  {$IFDEF TESTINSIGHT}
  {$DEFINE UseVCL}
  TestInsight.Client,
  TestInsight.DUnitX,
  {$ENDIF}
  {$IFDEF UseVCL}
  VCL.Forms,
  DUnitx.Loggers.GUI.VCL,
  {$ENDIF }
  {$IFDEF UseConsole}
  DUnitX.Loggers.Console,
  {$ENDIF }
  DUnitX.TestFramework,
  TestingUnit in 'TestingUnit.pas';

{$IFDEF TESTINSIGHT}
function IsTestInsightRunning: Boolean;
var
  client: ITestInsightClient;
begin
  client := TTestInsightRestClient.Create;
  client.StartedTesting(0);
  Result := not client.HasError;
end;
{$ENDIF}

begin
  {$IFDEF TESTINSIGHT}
  if IsTestInsightRunning then
  begin
    TestInsight.DUnitX.RunRegisteredTests;
    exit;
  end;
  {$ENDIF}


  try

    {$IFDEF UseVCL}
    Application.Initialize;
    Application.CreateForm(TGUIVCLTestRunner, GUIVCLTestRunner);
    Application.Run;
    {$ENDIF}
    {$IFDEF UseConsole}
    //Check command line options, will exit if invalid
    TDUnitX.CheckCommandLine;
    //Create the test runner
    var runner := TDUnitX.CreateRunner;
    //Tell the runner to use RTTI to find Fixtures
    runner.UseRTTI := True;
    //When true, Assertions must be made during tests;
    runner.FailsOnNoAsserts := False;

    //tell the runner how we will log things
    //Log to the console window if desired
    if TDUnitX.Options.ConsoleMode <> TDunitXConsoleMode.Off then
    begin
      var logger := TDUnitXConsoleLogger.Create(TDUnitX.Options.ConsoleMode = TDunitXConsoleMode.Quiet);
      runner.AddLogger(logger);
    end;
    //Generate an NUnit compatible XML File
    var nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
    runner.AddLogger(nunitLogger);

    //Run tests
    var 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}
    {$ENDIF}
  except
    on E: Exception do
      System.Writeln(E.ClassName, ': ', E.Message);
  end;

 

 

Share this post


Link to post
12 hours ago, Dave Novo said:

The workaround I have found is to find my shortest test and hit Alt+F9. Then all the tests get registered.

You can also just hit >> 
This will run no test at all, but populate the window with all available tests. 

  • Like 1

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

×