0

I'm using nunit3-console runner for my Selenium tests project. After tests were run I find TestResult.xml file in folder from where I've started nunit3-console runner. Also the destination path of this file can be specified in command line using "--result" option. At the end of the tests I wish to collect all logs and reports into my custom specific folder.

How can I get programmatically current path (either default or specified in command line) for TestResult.xml file, to be sure, that its copying or moving always will be successful?

Is it possible to set/override this option in program code?

Sančiezz
  • 81
  • 2
  • 11
  • It's not clear from your question why setting the path using `--result` or `--work` in the command-line isn't satisfactory to you. What do you mean by "How can I get programmatically?" In what program, for example? – Charlie Mar 17 '21 at 15:11
  • @Charlie Setting the path using `--result` or `--work` in the command-line is not satisfactory to me, because these values always have to be in sync with other paths in my tests, and it will duplicate some of those paths. In my test project I want always know where this file will be generated, and then perform it moving to my custom log folder, where I gather different logs of various applications, reports and other artifacts without carrying about synchronizing of this path multiple times in different places. I just want to know as soon as possible the path where this XML will be generated. – Sančiezz Mar 18 '21 at 06:58

1 Answers1

0

I asked in what code you wanted to do this, since you may have meant various things, like a stand-alone test runner, an engine extension, etc. It sounds like you mean in your test code, so that's what I'm answering.

Ideally, you should set the directory in which you want all output from NUnit itself or from your tests to be saved. This is done using the --work option, which sets the NUnit "Work Directory." Note this is not the usual "working directory" but a term that NUnit uses to mean the directory for output reports.

If you specify a file name or relative path for result output in the command-line, it is interpreted relative to the Work Directory.

If you need to create a file in the same place yourself, you can retrieve the work directory using TestContext.CurrentContext.WorkDirectory.

Charlie
  • 12,928
  • 1
  • 27
  • 31