Skip to content

Commit

Permalink
Support consele generate jounral (DynamoDS#102)
Browse files Browse the repository at this point in the history
* Supports Console.exe run with specified RevitPath

* Update ReadMe file

* Update install exe file

* Update .net to 48 & Support create single test Journal for export

* Update README

* Support Console creating single test Journal files for export

* Update Install exe file

* Update ReadMe

* Dont set WorkingDirectory default when export journal files
  • Loading branch information
ZiyunShang authored Apr 27, 2020
1 parent 6a110dc commit 2df663b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 40 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ A console application which allows running RTF without a user interface. If you'
```
Options:
--dir=[VALUE] The full path to the working directory. The working directory is the directory in which RTF will generate the journal and the addin to Run Revit. Revit's run-by-journal capability requires that all addins which need to be loaded are in the same directory as the journal file. So, if you're testing other addins on top of Revit using RTF, you'll need to put those addins in whatever directory you specify as the working directory.
-a, --assembly=[VALUE] The full path to the assembly containing your tests.
-r, --results=[VALUE] This is the full path to an .xml file that will contain the results.
-f, --fixture=[VALUE] The full name (with namespace) of a test fixture to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly.(OPTIONAL)
-t, --testName[=VALUE] The name of a test to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly. (OPTIONAL)
--category[=VALUE] The name of a test category to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly. (OPTIONAL)
--exclude[=VALUE] The name of a test category to exclude. This has a higher priortiy than other settings. If a specified category is set here, any test cases that belongs to that category will not be run. (OPTIONAL)
-c, --concatenate Concatenate the results from this run of RTF with an existing results file if one exists at the path specified. The default behavior is to replace the existing results file. (OPTIONAL)
--revit[=VALUE] The Revit executable to be used for testing. If no executable is specified, RTF will use the first version of Revit that is found on the machine using the RevitAddinUtility. (OPTIONAL)
--copyAddins Specify whether to copy the addins from the Revit folder to the current working directory. Copying the addins from the Revit folder will cause the test process to simulate the typical setup on your machine. (OPTIONAL)
--dry Conduct a dry run. (OPTIONAL)
-x, --clean Cleanup journal files after test completion. (OPTIONAL)
--continuous Run all selected tests in one Revit session. (OPTIONAL)
--groupByModel Run tests with same model without reopening the model for faster execution, requires --continuous. (OPTIONAL)
--time The time, in milliseconds, after which RTF will close the testing process automatically. (OPTIONAL)
-d, --debug Should RTF attempt to attach to a debugger?. (OPTIONAL)
-h, --help Show this message and exit. (OPTIONAL)
--dir=[VALUE] The full path to the working directory. The working directory is the directory in which RTF will generate the journal and the addin to Run Revit. Revit's run-by-journal capability requires that all addins which need to be loaded are in the same directory as the journal file. So, if you're testing other addins on top of Revit using RTF, you'll need to put those addins in whatever directory you specify as the working directory.
-a, --assembly=[VALUE] The full path to the assembly containing your tests.
-r, --results=[VALUE] This is the full path to an .xml file that will contain the results.
-f, --fixture=[VALUE] The full name (with namespace) of a test fixture to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly.(OPTIONAL)
-t, --testName[=VALUE] The name of a test to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly. (OPTIONAL)
--category[=VALUE] The name of a test category to run. If no fixture, no category and no test names are specified, RTF will run all tests in the assembly. (OPTIONAL)
--exclude[=VALUE] The name of a test category to exclude. This has a higher priortiy than other settings. If a specified category is set here, any test cases that belongs to that category will not be run. (OPTIONAL)
-c, --concatenate Concatenate the results from this run of RTF with an existing results file if one exists at the path specified. The default behavior is to replace the existing results file. (OPTIONAL)
--revit[=VALUE] The Revit executable to be used for testing. If no executable is specified, RTF will use the first version of Revit that is found on the machine using the RevitAddinUtility. (OPTIONAL)
--copyAddins Specify whether to copy the addins from the Revit folder to the current working directory. Copying the addins from the Revit folder will cause the test process to simulate the typical setup on your machine. (OPTIONAL)
--dry Conduct a dry run. (OPTIONAL)
-x, --clean Cleanup journal files after test completion. (OPTIONAL)
--continuous Run all selected tests in one Revit session. (OPTIONAL)
--groupByModel Run tests with same model without reopening the model for faster execution, requires --continuous. (OPTIONAL)
--isExport Export the journal file for each wanted test. (OPTIONAL)
--journalSample=[VALUE] A sample file for export. (OPRIONAL)
--exportFolder=[VALUE] A folder to store the export journal files. (OPTIONAL)
--time The time, in milliseconds, after which RTF will close the testing process automatically. (OPTIONAL)
-d, --debug Should RTF attempt to attach to a debugger?. (OPTIONAL)
-h, --help Show this message and exit. (OPTIONAL)
```

As an example, the following command:
Expand Down Expand Up @@ -82,6 +85,11 @@ WARNING: One or more journal files could not be deleted.
The warning about some journal files not being deleted can be safely ignored.
You can use console application to generate Journal files for exporting:
```
RevitTestFrameworkConsole.exe -a MyTest.dll -t:[TestName] --isExport --journalSample MyJournalSample.txt --exportFolder C:\MyFolder
```
### RevitTestFrameworkGUI.exe
Provides a visual interface for you to choose tests from a treeview and to visualize the results of the tests as they are run. The same settings provided in the command line argument help above are available in the UI. The UI also allows you to save your testing session.
Expand Down
7 changes: 6 additions & 1 deletion src/Applications/RevitTestFrameworkApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ static void Main(string[] args)

runner = new Runner(setupData);

Run();
if(runner.IsExport)
{
runner.ExportJournal();
}
else
Run();
}
catch (Exception ex)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Applications/RevitTestFrameworkGUI/RunnerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public class RunnerViewModel : NotificationObject
private int skippedTestCount;
private int failedTestCount;

private string journalSamplePath = "";
private bool isExport = false;

#endregion

#region public properties
Expand Down Expand Up @@ -311,10 +308,10 @@ public string WorkingDirectory

public string JournalSample
{
get { return journalSamplePath; }
get { return runner.JournalSample; }
set
{
journalSamplePath = value;
runner.JournalSample = value;
RaisePropertyChanged();
}
}
Expand Down Expand Up @@ -350,14 +347,17 @@ public bool GroupByModel
}
}

/// <summary>
/// True to export the journal file for each selected test
/// </summary>
public bool IsExport
{
get { return isExport; }
get { return runner.IsExport; }
set
{
if (isExport != value)
if (runner.IsExport != value)
{
isExport = value;
runner.IsExport = value;
RaisePropertyChanged();
ExportCommand.RaiseCanExecuteChanged();
}
Expand Down Expand Up @@ -1075,8 +1075,8 @@ private void ExportJournal()

if (dirs.ShowDialog() == DialogResult.OK)
{
String ExportFolder = dirs.SelectedPath;
runner.ExportJournal(ExportFolder, JournalSample);
runner.ExportFolder = dirs.SelectedPath;
runner.ExportJournal();
}
}

Expand Down
57 changes: 45 additions & 12 deletions src/Framework/Runner/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ public bool CancelRequested

public bool GroupByModel { get; set; }

/// <summary>
/// True to export the journal file for each selected test
/// </summary>
public bool IsExport { get; set; }

public string JournalSample { get; set; }

public string ExportFolder { get; set; }

public List<SelectionHint> SelectionHints { get; set; } = new List<SelectionHint>();

public GroupingType GroupingType
Expand Down Expand Up @@ -332,7 +341,8 @@ public Runner(IRunnerSetupData setupData)

if (String.IsNullOrEmpty(setupData.WorkingDirectory) || !Directory.Exists(setupData.WorkingDirectory))
{
setupData.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if(!(setupData as RunnerSetupData).IsExport)
setupData.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

if (!String.IsNullOrEmpty(setupData.Category))
Expand All @@ -359,6 +369,9 @@ public Runner(IRunnerSetupData setupData)
IsTesting = setupData.IsTesting;
ExcludedCategory = setupData.ExcludedCategory;
CopyAddins = (setupData as RunnerSetupData).CopyAddins;
IsExport = (setupData as RunnerSetupData).IsExport;
JournalSample = (setupData as RunnerSetupData).JournalSample;
ExportFolder = (setupData as RunnerSetupData).ExportFolder;

Initialize();
}
Expand Down Expand Up @@ -769,13 +782,13 @@ public static Runner Load(string filePath)
}
}

public void ExportJournal(String DstDir, String JournalSample)
public void ExportJournal()
{
var runnable = GetRunnableTests();

foreach(var test in runnable)
{
SetupJournalForExport(test, DstDir, JournalSample);
SetupJournalForExport(test);
}
}

Expand Down Expand Up @@ -859,7 +872,8 @@ private void ConductInitializationChecks()

if (String.IsNullOrEmpty(WorkingDirectory) || !Directory.Exists(WorkingDirectory))
{
WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if(!IsExport)
WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

if (!String.IsNullOrEmpty(Category))
Expand Down Expand Up @@ -1496,13 +1510,13 @@ private void DeleteAddins()
CopiedAddins.Clear();
}

private void SetupJournalForExport(ITestData td, String DstDir, String JournalSample)
private void SetupJournalForExport(ITestData td)
{
var JournalPath = Path.Combine(DstDir, td.Name + ".txt");
CreateJournalForExport(JournalPath, JournalSample, td.Name, td.Fixture.Name, td.Fixture.Assembly.Path, td.ModelPath);
var JournalPath = Path.Combine(ExportFolder, td.Name + ".txt");
CreateJournalForExport(JournalPath, td.Name, td.Fixture.Name, td.Fixture.Assembly.Path, td.ModelPath);
}

private void CreateJournalForExport(string path, string JournalSample, string testName, string fixtureName, string assemblyPath, string modelPath)
private void CreateJournalForExport(string path, string testName, string fixtureName, string assemblyPath, string modelPath)
{
string content = "";
StreamReader sr = new StreamReader(JournalSample);
Expand Down Expand Up @@ -1904,6 +1918,9 @@ public static IRunnerSetupData ParseCommandLineArguments(IEnumerable<string> arg
{"x|clean", "Cleanup journal files after test completion. (OPTIONAL)", v=> setupData.CleanUp = v != null},
{"continuous", "Run all selected tests in one Revit session. (OPTIONAL)", v=> setupData.Continuous = v != null},
{"groupByModel", "Run tests with same model without reopening the model for faster execution, requires continuous. (OPTIONAL)", v=> setupData.GroupByModel = v != null },
{"isExport","Export the journal file for each wanted test. (OPTIONAL)",v=> setupData.IsExport = v != null },
{"journalSample=","A sample file for export. (OPRIONAL)", v=> setupData.JournalSample = Path.GetFullPath(v)},
{"exportFolder=","A folder to store the export journal files. (OPTIONAL)", v=> setupData.ExportFolder = Path.GetFullPath(v)},
{"time", "The time, in milliseconds, after which RTF will close the testing process automatically. (OPTIONAL)", v=>setupData.Timeout = Int32.Parse(v) },
{"d|debug", "Should RTF attempt to attach to a debugger?. (OPTIONAL)", v=>setupData.IsDebug = v != null },
{"h|help", "Show this message and exit. (OPTIONAL)", v=> showHelp = v != null }
Expand Down Expand Up @@ -1934,19 +1951,35 @@ public static IRunnerSetupData ParseCommandLineArguments(IEnumerable<string> arg
throw new Exception();
}

if (string.IsNullOrEmpty(setupData.WorkingDirectory))
if (string.IsNullOrEmpty(setupData.WorkingDirectory) && !setupData.IsExport)
{
throw new Exception("You must specify a working directory.");
throw new Exception("You must specify a working directory except for export journal.");
}

if (string.IsNullOrEmpty(setupData.TestAssembly))
{
throw new Exception("You must specify a test assembly.");
}

if (string.IsNullOrEmpty(setupData.Results))
if (string.IsNullOrEmpty(setupData.Results) && !setupData.IsExport)
{
throw new Exception("You must specify a results file except for export journal.");
}

if(setupData.IsExport)
{
throw new Exception("You must specify a results file.");
if(setupData.Continuous || setupData.GroupByModel)
{
throw new Exception("You should not set Continuous or GroupByModel when you want to export journal files.");
}
if(string.IsNullOrEmpty(setupData.JournalSample) || !File.Exists(setupData.JournalSample))
{
throw new Exception("You should set a JournalSample File!");
}
if(string.IsNullOrEmpty(setupData.ExportFolder) || !Directory.Exists(setupData.ExportFolder))
{
throw new Exception("You should specify an Export folder to store the exported journal files.");
}
}

return setupData;
Expand Down
3 changes: 3 additions & 0 deletions src/Framework/Runner/RunnerSetupData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class RunnerSetupData : IRunnerSetupData
public bool CopyAddins { get; set; }
public bool IsTesting { get; set; }
public int SelectedProduct { get; set; }
public bool IsExport { get; set; }
public string JournalSample { get; set; }
public string ExportFolder { get; set; }

public RunnerSetupData()
{
Expand Down
Binary file modified tools/Output/RevitTestFrameworkInstallerPreview.exe
Binary file not shown.

0 comments on commit 2df663b

Please sign in to comment.