Testing "script-level" code This topic contains 3 replies, has 2 voices, and was last updated by Dave Brannan 1 week, 3 days ago. Author Posts October 5, 2017 at 10:30 am #81298 Dave BrannanParticipant Hi, What is everyone's approach to testing a script (i.e. a self-contained ps1 that contains parameters, functions, and code)? Rather than a module that contains a function per file. Basically same as https://github.com/pester/Pester/issues/21 Would you always refactor to a module, or extract a function definition out of the script file (to avoid dot-sourcing?) Dave. October 5, 2017 at 12:51 pm #81311 Dave BrannanParticipant To answer my own question, I've found a post by Jakub with possible solutions. http://web.archive.org/web/20160112151907/http://jakubjares.com/blog/2015/01/10/test-powershell-scripts-end-to-end-with-pester/ Not sure if Pester 4.0 has any other solutions? October 6, 2017 at 2:31 pm #81478 Adam BertramModerator Unfortunately, there is no good way to do it. Pester loves functions and if your code is broken up into functions, it makes your code not only cleaner but easier to test. Before you spend too much time trying to get this to work I'd first look to see if you can split out that script into multiple functions and then write tests for those. October 6, 2017 at 3:42 pm #81484 Dave BrannanParticipant I've gone with the UnderTest switch for now. Problem is it's not my code and I'm fine with recommending it gets re-factored, but hoped there might now be an easier way to extract a function (for example). Thanks for the reply Adam. Author Posts You must be logged in to reply to this topic.