Agile/Scrum blog

Onderwerp: TDD

Starting TDD with legacy code

Harm Pauw Door: Harm Pauw,  13-12-2016
Onderwerp: TDD  Craftsmanship  refactoring  

One of the questions people that want to start with Test Driven Development ask regularly is: “I find starting with TDD on an existing project hard. How do you get old legacy code testable?”. Unfortunately, one of the most common answers to that question is: “You just have to begin and take small steps.” And while the answer has truth in it, it’s also a much too simple answer that doesn’t really help you to start. How come and what is a better answer to the question on how to start?

Creating a unit testing framework for PowerShell - Part 6

Prajeesh Prathap Door: Prajeesh Prathap,  21-01-2015
Onderwerp: PowerShell  unit testing  TDD  

The authorization manager helps control the execution of commands for the runspace. When you try to execute a PowerShell script from C#, and haven’t changed PowerShell’s default execution policy, the scripts that are executed under the execution policy set on the machine. If you want the tests executed from C# to bypass the default security policy, then you need to either use a null AuthorizationManager implementation for the runspace or create a custom implementation of the AuthorizationManager and override the policy based on any condition you have. Deriving from the AuthorizationManager class allows you to override the ShouldRun method and add the logic specific to your needs like set up a reason parameter with a custom execption with proper explanation and  details on why this command was blocked etc. Read more..

Creating a unit testing framework for PowerShell - Part 5

Prajeesh Prathap Door: Prajeesh Prathap,  21-01-2015
Onderwerp: PowerShell  unit testing  TDD  

PowerShell cmdlets and modules can report two kinds or errors (Terminating and non-terminating). Terminating errors are errors that cause the pipeline to be terminated immediately, or errors that occur when there is no reason to continue processing. Nonterminating errors are those errors that report a current error condition, but the cmdlet can continue to process input objects. With nonterminating errors, the user is  typically notified of the problem, but the cmdlet continues to process the next input object. Terminating errors are reported by throwing  exceptions or by calling the ThrowTerminatingError method, while non-terminating errors are reported by calling the Write-Error method that in turn sends an error record to the error stream. Read more..

Creating a unit testing framework for PowerShell - Part 4

Prajeesh Prathap Door: Prajeesh Prathap,  18-01-2015
Onderwerp: PowerShell  unit testing  TDD  

Before we proceed into how we can stub out commands in our test framework, we’ll see how the AddScript method works and how to use it to execute a script block in powershell. The AddScript method adds a script to the end of the pipeline of the PowerShell object and can be invoked by the Invoke method. We’ll use this method to add our dummy function as a script object to the pipeline so that when this command is called later from a function, it’s going to call the dummy function that was added using the AddScript method. Read mode..

Creating a unit testing framework for PowerShell - Part 3

Prajeesh Prathap Door: Prajeesh Prathap,  17-01-2015
Onderwerp: PowerShell  unit testing  TDD  

The windows PowerShell engine can be hosted in the System.Management.Automation.PowerShell class. Using this class you can create, execute and manage commands in a Runspace. We’ll use these features of the PowerShell class to load and execute our Modules and interact with the PowerShell engine whenever needed in our unit test framework. While creating the PowerShell host for our test framework, it’s good to define the Runspace that is responsible for the operating environment for command pipelines. In our framework I preferred to use the constrained runspace which will allow us to restrict the programming elements that can be applied by the user. Read more..

Creating a unit testing framework for PowerShell - Part 2

Prajeesh Prathap Door: Prajeesh Prathap,  17-01-2015
Onderwerp: PowerShell  unit testing  TDD  

Before we dig into the testing process, one of the main activities to be done as part of the Arrange phase is to populate or ModuleObject properties with the CommandInfo object that is used at the Acting phase of our test framework. For iterating through all the properties and reading the attributes using reflection and setting the values of the ModuleObject implementation, we’ll make use of the Visitor pattern. Read more..

Creating a unit testing framework for PowerShell - Part 1

Prajeesh Prathap Door: Prajeesh Prathap,  17-01-2015
Onderwerp: PowerShell  unit testing  TDD  

Recently I started working on a light weight unit testing framework for my PowerShell modules. There are a lot of testing frameworks for  PowerShell that can be executed as script files from a PS host, but not many allows you to integrate with VSTests and write test methods and classes in C#.
The following posts in this series is about how you can create a unit testing framework for Windows PowerShell and use it.
 
Being a big fan of the Page objects pattern and have seen the benefits of how easily you can model a page and reduce the amount of duplicate code when creating UI tests for websites, I wanted to do something similar modules for PowerShell also. So when I started writing the framework, one of the main considerations was to simplify my testing process by modelling a PowerShell module in code. Read more..