|
| 1 | +program DUnitXExamples_D12Athens; |
| 2 | + |
| 3 | +{$IFNDEF TESTINSIGHT} |
| 4 | +{$APPTYPE CONSOLE} |
| 5 | +{$ENDIF} |
| 6 | +{$STRONGLINKTYPES ON} |
| 7 | + |
| 8 | +uses |
| 9 | + System.SysUtils, |
| 10 | + {$IFDEF TESTINSIGHT} |
| 11 | + TestInsight.DUnitX, |
| 12 | + {$ENDIF} |
| 13 | + System.Diagnostics, |
| 14 | + DUnitX.Examples.General in 'DUnitX.Examples.General.pas', |
| 15 | + DUnitX.ConsoleWriter.Base in '..\Source\DUnitX.ConsoleWriter.Base.pas', |
| 16 | + DUnitX.DUnitCompatibility in '..\Source\DUnitX.DUnitCompatibility.pas', |
| 17 | + DUnitX.Generics in '..\Source\DUnitX.Generics.pas', |
| 18 | + DUnitX.InternalInterfaces in '..\Source\DUnitX.InternalInterfaces.pas', |
| 19 | + DUnitX.ServiceLocator in '..\Source\DUnitX.ServiceLocator.pas', |
| 20 | + DUnitX.Loggers.Console in '..\Source\DUnitX.Loggers.Console.pas', |
| 21 | + DUnitX.Loggers.Text in '..\Source\DUnitX.Loggers.Text.pas', |
| 22 | + DUnitX.Loggers.XML.NUnit in '..\Source\DUnitX.Loggers.XML.NUnit.pas', |
| 23 | + DUnitX.Loggers.XML.xUnit in '..\Source\DUnitX.Loggers.XML.xUnit.pas', |
| 24 | + DUnitX.MacOS.Console in '..\Source\DUnitX.MacOS.Console.pas', |
| 25 | + DUnitX.Test in '..\Source\DUnitX.Test.pas', |
| 26 | + DUnitX.TestFixture in '..\Source\DUnitX.TestFixture.pas', |
| 27 | + DUnitX.TestFramework in '..\Source\DUnitX.TestFramework.pas', |
| 28 | + DUnitX.TestResult in '..\Source\DUnitX.TestResult.pas', |
| 29 | + DUnitX.RunResults in '..\Source\DUnitX.RunResults.pas', |
| 30 | + DUnitX.TestRunner in '..\Source\DUnitX.TestRunner.pas', |
| 31 | + DUnitX.Utils in '..\Source\DUnitX.Utils.pas', |
| 32 | + DUnitX.Utils.XML in '..\Source\DUnitX.Utils.XML.pas', |
| 33 | + DUnitX.WeakReference in '..\Source\DUnitX.WeakReference.pas', |
| 34 | + DUnitX.Windows.Console in '..\Source\DUnitX.Windows.Console.pas', |
| 35 | + DUnitX.StackTrace.EurekaLog7 in '..\Source\DUnitX.StackTrace.EurekaLog7.pas', |
| 36 | + NonNamespacedExample in 'NonNamespacedExample.pas', |
| 37 | + DUnitX.Examples.EqualityAsserts in 'DUnitX.Examples.EqualityAsserts.pas', |
| 38 | + DUnitX.FixtureResult in '..\Source\DUnitX.FixtureResult.pas', |
| 39 | + DUnitX.Loggers.Null in '..\Source\DUnitX.Loggers.Null.pas', |
| 40 | + DUnitX.MemoryLeakMonitor.Default in '..\Source\DUnitX.MemoryLeakMonitor.Default.pas', |
| 41 | + DUnitX.Extensibility in '..\Source\DUnitX.Extensibility.pas', |
| 42 | + DUnitX.CommandLine.OptionDef in '..\Source\DUnitX.CommandLine.OptionDef.pas', |
| 43 | + DUnitX.CommandLine.Options in '..\Source\DUnitX.CommandLine.Options.pas', |
| 44 | + DUnitX.CommandLine.Parser in '..\Source\DUnitX.CommandLine.Parser.pas', |
| 45 | + DUnitX.FixtureProvider in '..\Source\DUnitX.FixtureProvider.pas', |
| 46 | + DUnitX.Timeout in '..\Source\DUnitX.Timeout.pas', |
| 47 | + DUnitX.Attributes in '..\Source\DUnitX.Attributes.pas', |
| 48 | + DUnitX.Linux.Console in '..\Source\DUnitX.Linux.Console.pas', |
| 49 | + ProviderExample in 'ProviderExample.pas', |
| 50 | + DUnitX.FixtureBuilder in '..\Source\DUnitX.FixtureBuilder.pas', |
| 51 | + DUnitX.FilterBuilder in '..\Source\DUnitX.FilterBuilder.pas', |
| 52 | + DUnitX.Filters in '..\Source\DUnitX.Filters.pas', |
| 53 | + DUnitX.Loggers.XML.JUnit in '..\Source\DUnitX.Loggers.XML.JUnit.pas', |
| 54 | + DUnitX.OptionsDefinition in '..\Source\DUnitX.OptionsDefinition.pas'; |
| 55 | + |
| 56 | + { keep comment here to protect the following conditional from being removed by the IDE when adding a unit } |
| 57 | +{$IFNDEF TESTINSIGHT} |
| 58 | +var |
| 59 | + runner : ITestRunner; |
| 60 | + results : IRunResults; |
| 61 | + logger : ITestLogger; |
| 62 | + stopWatch : TStopWatch; |
| 63 | + {$IFDEF CI} |
| 64 | + nunitLogger : ITestLogger; |
| 65 | + {$ENDIF} |
| 66 | +{$ENDIF} |
| 67 | +begin |
| 68 | + {$IFDEF TESTINSIGHT} |
| 69 | + TestInsight.DUnitX.RunRegisteredTests; |
| 70 | + {$ELSE} |
| 71 | + |
| 72 | + try |
| 73 | + //Check command line options, will exit if invalid |
| 74 | + TDUnitX.CheckCommandLine; |
| 75 | + //Create the runner |
| 76 | + runner := TDUnitX.CreateRunner; |
| 77 | + //Tell the runner to use RTTI to find Fixtures |
| 78 | + runner.UseRTTI := True; |
| 79 | + //When true, Assertions must be made during tests; |
| 80 | + runner.FailsOnNoAsserts := False; |
| 81 | + {$IFNDEF CI} |
| 82 | + TDUnitX.Options.ExitBehavior := TDUnitXExitBehavior.Pause; |
| 83 | + {$ELSE} |
| 84 | + //no point logging to the console, CI server will use the xml results and exit code. |
| 85 | + TDUnitX.Options.ConsoleMode := TDunitXConsoleMode.Off; |
| 86 | + {$ENDIF} |
| 87 | + //tell the runner how we will log things |
| 88 | + //Log to the console window if desired |
| 89 | + if TDUnitX.Options.ConsoleMode <> TDunitXConsoleMode.Off then |
| 90 | + begin |
| 91 | + logger := TDUnitXConsoleLogger.Create(TDUnitX.Options.ConsoleMode = TDunitXConsoleMode.Quiet); |
| 92 | + runner.AddLogger(logger); |
| 93 | + end; |
| 94 | + |
| 95 | + {$IFDEF CI} |
| 96 | + nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile); |
| 97 | + runner.AddLogger(nunitLogger); |
| 98 | + {$ENDIF} |
| 99 | + |
| 100 | + //Run tests |
| 101 | + stopWatch := TStopWatch.StartNew; |
| 102 | + results := runner.Execute; |
| 103 | + stopWatch.Stop; |
| 104 | + |
| 105 | + {$IFNDEF CI} |
| 106 | + if TDUnitX.Options.ConsoleMode <> TDunitXConsoleMode.Off then |
| 107 | + System.Write(Format('Done in %d ms.. press <Enter> key to quit.', [stopWatch.ElapsedMilliseconds])); |
| 108 | + |
| 109 | + //We don't want this happening when running under CI. |
| 110 | + if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then |
| 111 | + System.Readln; |
| 112 | + {$ENDIF} |
| 113 | + |
| 114 | + except |
| 115 | + on E: Exception do |
| 116 | + System.Writeln(E.ClassName, ': ', E.Message); |
| 117 | + end; |
| 118 | + {$ENDIF} |
| 119 | +end. |
0 commit comments