<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>www.hans-eric.com</title>
	<atom:link href="https://www.hans-eric.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.hans-eric.com</link>
	<description>Hans-Eric Grönlund on software development</description>
	<lastBuildDate>Tue, 12 Jul 2022 12:55:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>PowerShell TDD: Testing ShouldProcess</title>
		<link>https://www.hans-eric.com/2022/07/12/powershell-tdd-testing-shouldprocess/</link>
					<comments>https://www.hans-eric.com/2022/07/12/powershell-tdd-testing-shouldprocess/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Tue, 12 Jul 2022 12:55:07 +0000</pubDate>
				<category><![CDATA[Anouncements]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[TDDSeams]]></category>
		<category><![CDATA[test-driven]]></category>
		<category><![CDATA[TDD]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=809</guid>

					<description><![CDATA[The built-in PowerShell feature ShouldProcess is considered best practice for commands that perform destructive operations. The problem with ShouldProcess is that it may prompt the user for manual confirmation, which makes automated testing difficult or impractical. The normal approach to automate testing of processes that involves manual prompting is to mock the part which performs [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>The built-in PowerShell feature <a href="https://docs.microsoft.com/sv-se/powershell/scripting/learn/deep-dives/everything-about-shouldprocess">ShouldProcess</a> is considered best practice for commands that perform destructive operations.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Remove-Something {
    &#x5B;CmdletBinding(SupportsShouldProcess)]
    param()
    if ($PSCmdlet.ShouldProcess(&quot;Something&quot;, &quot;Permanently remove&quot;)) {
        # Code that performs the destructive operation
    }
}
</pre></div>


<p>The problem with ShouldProcess is that it may prompt the user for manual confirmation, which makes automated testing difficult or impractical. The normal approach to automate testing of processes that involves manual prompting is to mock the part which performs it. However, since ShouldProcess is a .NET method on an automatic context variable (<a href="https://docs.microsoft.com/sv-se/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2#pscmdlet">$PSCmdlet</a>), testing frameworks like <a href="https://github.com/pester/Pester">Pester</a> aren&#8217;t able to replace its implementation with a mock.</p>



<p>Fortunately, there is a way to make ShouldProcess adhering commands fully testable. It just requires a little bit of extra work, such as wrapping ShouldProcess into a PowerShell function of its own.</p>



<h3 class="wp-block-heading">Wrapping ShouldProcess</h3>



<p>Here&#8217;s a PowerShell function that wraps the ShouldProcess method and makes it possible to use mocks to bypass the prompting.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Invoke-ShouldProcess {
    # Suppress the PSShouldProcess warning since we&#039;re wrapping ShouldProcess to be able to mock it from a Pester test.
    # Info on suppressing PSScriptAnalyzer rules can be found here:
    # https://github.com/PowerShell/PSScriptAnalyzer/blob/master/README.md#suppressing-rules
    &#x5B;Diagnostics.CodeAnalysis.SuppressMessageAttribute(&#039;PSShouldProcess&#039;, &#039;&#039;)]
    &#x5B;CmdletBinding()]
    param (
        &#x5B;Parameter(Mandatory)]
        &#x5B;System.Management.Automation.PSCmdlet]
        $Context,
        &#x5B;Parameter(Mandatory)]
        &#x5B;string]
        $Target,
        &#x5B;Parameter(Mandatory)]
        &#x5B;string]
        $Operation,
        &#x5B;string]
        $Message
    )
    if ($Message) {
        $Context.ShouldProcess($Message, $Target, $Operation)
    } else {
        $Context.ShouldProcess($Target, $Operation)
    }
}
</pre></div>


<p>Actually, there are <a href="https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.cmdlet.shouldprocess?view=powershellsdk-7.0.0#overloads">four overloads of the ShouldProcess method</a>, but the code above only handles the two most useful ones (in my opinion).</p>



<p>The next step is to replace the ShouldProcess method in the command, and use the wrapper instead.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Remove-Something {
    &#x5B;CmdletBinding(SupportsShouldProcess)]
    param()
    if (Invoke-ShouldProcess -Context $PSCmdlet -Target &quot;Something&quot; -Operation &quot;Permanently remove&quot;) {
        # Code that performs the destructive operation
    }
}
</pre></div>


<p>Note that you need to provide the command&#8217;s $PSCmdlet variable as the context on which ShouldProcess should be invoked.</p>



<h3 class="wp-block-heading">Mocking Invoke-ShouldProcess</h3>



<p>Now our command is ready for some Pester testing. Here are a couple of test stubs that show you how to mock the wrapper. Hopefully, you&#8217;ll be able to take it from here and start testing your own ShouldProcess-aware commands.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
It &#039;Should perform the operation if the user confirms&#039; {
    Mock Invoke-TDDShouldProcess { $true }

    Remove-Something
        
    # Code that verifies that the operation was executed
}

It &#039;Should not perform the operation if the user aborts&#039; {
    Mock Invoke-TDDShouldProcess { $false }

    Remove-Something

    # Code that verifies that the operation was not executed
}
</pre></div>


<h3 class="wp-block-heading">Introducing TDDSeams</h3>



<p>I have created a PowerShell module named <a href="https://github.com/hansEricG/TDDSeams">TDDSeams</a> which has wrappers for ShouldProcess and its sister ShouldContinue, as well as a couple of helper methods that implement the best practice behavior described by Kevin Marquette in his excellent post <a href="https://powershellexplained.com/2020-03-15-Powershell-shouldprocess-whatif-confirm-shouldcontinue-everything/">Everything you wanted to know about ShouldProcess</a>.</p>



<p>You can install the TDDSeams module from an elevated PowerShell with the following command.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
Install-Module TDDSeams
</pre></div>


<p>Also, if you are interested in test-driven PowerShell development, check out my previous post <a href="https://www.hans-eric.com/2022/07/11/powershell-tdd-testing-cmdletbinding-and-outputtype">PowerShell TDD: Testing CmdletBinding and OutputType</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2022/07/12/powershell-tdd-testing-shouldprocess/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PowerShell TDD: Testing CmdletBinding and OutputType</title>
		<link>https://www.hans-eric.com/2022/07/11/powershell-tdd-testing-cmdletbinding-and-outputtype/</link>
					<comments>https://www.hans-eric.com/2022/07/11/powershell-tdd-testing-cmdletbinding-and-outputtype/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Mon, 11 Jul 2022 10:03:44 +0000</pubDate>
				<category><![CDATA[Anouncements]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[TDDUtils]]></category>
		<category><![CDATA[test-driven]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[TDD]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=802</guid>

					<description><![CDATA[How to test if a PowerShell function has declared CmdletBinding or OutputType attributes. This is useful if you are serious about TDD in PowerShell.]]></description>
										<content:encoded><![CDATA[
<p>A while ago, I decided to add PowerShell to my automation toolbox. Since I believe the best way to learn a new language is to do <a href="https://www.agilealliance.org/glossary/tdd/">test-driven development</a> and PowerShell has a fantastic module for this, called <a href="https://pester.dev/docs/quick-start">Pester</a>. The framework is super intuitive, easy to do <a href="https://pester.dev/docs/usage/mocking">mocking</a> in, and allows you develop your code design from tests.</p>



<p>However, one thing bugged me. I didn&#8217;t seem to be able to write code that tested whether a function had declared <a href="https://docs.microsoft.com/sv-se/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-7.2">CmdletBinding</a> (i.e. was an <a href="https://www.scriptrunner.com/en/blog/powershell-advanced-functions/">Advanced Function</a>), or if it had declared <a href="https://4sysops.com/archives/understanding-the-outputtype-keyword-in-powershell/">OutputType</a>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
# How can I test this?
function MyFunction {
    &#x5B;CmdletBinding(SupportsShouldProcess, ConfirmImpact=&#039;High&#039;)]
    &#x5B;OutputType(&#039;String&#039;)]
    ...
}
</pre></div>


<p>Google didn&#8217;t have anything useful on this subject so <a href="https://stackoverflow.com/questions/67264521/how-to-test-that-a-powershell-function-has-a-cmdletbinding-attribute">I tried my luck on StackOverflow</a> and <a href="https://stackoverflow.com/users/3156906/mclayton">mclayton</a> pointed me in the right direction (although, as mclayton puts it: it&#8217;s a bit of a mouthful). It turns out that I can use the <a href="https://powershell.one/powershell-internals/parsing-and-tokenization/abstract-syntax-tree">built-in Abstract Syntax Tree</a> (AST) and specifically the Param block attributes to find out if CmdletBinding is declared.</p>



<h3 class="wp-block-heading">Testing CmdletBinding</h3>



<p>The below function takes a command as input and looks for a CmdletBinding param block attribute.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Test-CmdletBinding {
&#x5B;OutputType(&#x5B;Bool])]
&#x5B;CmdletBinding()]
    param (
        # Parameter help description
        &#x5B;Parameter(Mandatory)]
        &#x5B;System.Management.Automation.CommandInfo]
        $Command
    )

    $attribute = $command.ScriptBlock.Ast.Body.ParamBlock.Attributes | where-object { $_.TypeName.FullName -eq &#039;CmdletBinding&#039; };

    $null -ne $attribute
}
</pre></div>


<p>You can then use the helper function in a Pester test, like this.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
It &quot;Should be an advanced function&quot; {
    $c = Get-Command -Name MyCommand
    Test-CmdletBinding $c | Should -BeTrue
}
</pre></div>


<h3 class="wp-block-heading">Testing CmdletBinding Arguments</h3>



<p>That&#8217;s great, but what about arguments, like <a href="https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess?view=powershell-7.2">SupportsShouldProcess or ConfirmImpact</a>?</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
&#x5B;CmdletBinding(SupportsShouldProcess, ConfirmImpact=&#039;High&#039;)]
</pre></div>


<p>How can I test for those? Well, that&#8217;s where we get mouthful bits I guess, but the good news is that it&#8217;s doable. Here&#8217;s a helper function that can test those scenarios. It takes a command, an argument name, and an optional argument value and returns true if the command meets those conditions.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Test-CmdletBindingArgument {
    &#x5B;CmdletBinding()]
    &#x5B;OutputType(&#x5B;Bool])]
    param (
        # Parameter help description
        &#x5B;Parameter(Mandatory)]
        &#x5B;System.Management.Automation.CommandInfo]
        $Command,
        &#x5B;Parameter(Mandatory)]
        &#x5B;string]
        $ArgumentName,
        &#x5B;Parameter()]
        &#x5B;string]
        $ArgumentValue
    )

    $attribute = $command.ScriptBlock.Ast.Body.ParamBlock.Attributes | where-object { $_.TypeName.FullName -eq &#039;CmdletBinding&#039; };

    if ($attribute) {
        $argument = $attribute.NamedArguments | where-object { $_.ArgumentName -eq $ArgumentName };

        if ($null -eq $argument) {
            # The attribute does not have the argument, return false
            $false
        } elseif ($argument.ExpressionOmitted) {
            $ArgumentValue -eq &#039;&#039; -or $ArgumentValue -eq $true
        } elseif ($argument.Argument.Extent.Text -eq &#039;$true&#039;) {
            $ArgumentValue -eq &#039;&#039; -or $ArgumentValue -eq $true
        } elseif ($argument.Argument.Extent.Text -eq &#039;$false&#039;) {
            $ArgumentValue -eq $false
        } else {
            $ArgumentValue -eq $argument.Argument.Value
        }
    } else {
        # No such attribute exists on the command, return false
        $false
    }
}
</pre></div>


<p>The code handles both implicit and explicit values, e.g.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
&#x5B;CmdletBinding(SomeAttribute)]
&#x5B;CmdletBinding(SomeAttribute=$true)] # same as having the attribute declared
&#x5B;CmdletBinding(SomeAttribute=$false)] # same as not having the attribute declared
&#x5B;CmdletBinding(SomeAttribute=&#039;Some Value&#039;)]
</pre></div>


<p>Here are a couple of examples of Pester tests using the helper function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
It &quot;Should have CmdletBinding with ConfirmImpact set to High&quot; {
    $c = Get-Command -Name MyCommand
    Test-CmdletBindingArgument $c -ArgumentName &#039;ConfirmImpact&#039; -ArgumentValue &#039;High&#039; | Should -BeTrue
}

It &quot;Should have SupportShouldProcess declared&quot; {
    $c = Get-Command -Name MyCommand
    Test-CmdletBindingArgument $c -ArgumentName &#039;SupportShouldProcess&#039; | Should -BeTrue
}
</pre></div>


<h3 class="wp-block-heading">Testing OutputType</h3>



<p>Testing OutputType requires a slightly different approach. Since the OutputType attribute declares a type we have to access it through the positional arguments (instead of named arguments that were used for CmdletBinding).</p>



<p>Here&#8217;s a helper function to verify that a given command has declared a given type as its output type.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
function Test-OutputType {
    &#x5B;OutputType(&#x5B;Bool])]
    &#x5B;CmdletBinding()]
    param (
        # Parameter help description
        &#x5B;Parameter(Mandatory)]
        &#x5B;System.Management.Automation.CommandInfo]
        $Command,
        &#x5B;Parameter(Mandatory)]
        &#x5B;string]
        $TypeName
    )

    $attribute = $command.ScriptBlock.Ast.Body.ParamBlock.Attributes | where-object { $_.TypeName.FullName -eq &#039;OutputType&#039; };

    if ($attribute) {
        $argument = $attribute.PositionalArguments | where-object {
            if ($_.StaticType.Name -eq &#039;String&#039;) {
                $_.Value -eq $TypeName 
            } elseif ($_.StaticType.Name -eq &#039;Type&#039;) {
                $_.TypeName.Name -eq $TypeName 
            } else {
                $false
            }
        }
        if ($argument) {
            $true
        } else {
            $false
        }
    } else {
        $false
    }
}
</pre></div>


<p>Note that a type can be declared as a string or as a type, but the helper function handles both cases:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
&#x5B;OutputType(&#x5B;Bool])]
&#x5B;OutputType(&#039;System.Bool&#039;)]
</pre></div>


<p>And here&#8217;s an example of how it can be used within a Pester test.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
It &quot;Should have Output type Bool&quot; {
    $c = Get-Command -Name MyCommand
    Test-TDDOutputType $c -TypeName &#039;Bool&#039; | Should -BeTrue
}
</pre></div>


<h3 class="wp-block-heading">Introducing TDDUtils</h3>



<p>I have created a PowerShell module called <a href="https://github.com/hansEricG/TDDUtils">TDDUtils</a>, which contains the above functions (although named with a TDD prefix) as well as more general versions that allows you to test other attributes than CmdletBinding and OutputType.</p>



<p> You can install it from an Administrator PowerShell with the below command.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
Install-Module TDDUtils
</pre></div>


<p>I plan to add more useful functions to that module as I go on with my PowerShell TDD journey, and if you want to contribute or just give me some suggestions, feel free to contact <a href="https://mobile.twitter.com/hansericg">me on Twitter</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2022/07/11/powershell-tdd-testing-cmdletbinding-and-outputtype/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>iOS 6 Recipes Is Out</title>
		<link>https://www.hans-eric.com/2013/01/11/ios-6-recipes-is-out/</link>
					<comments>https://www.hans-eric.com/2013/01/11/ios-6-recipes-is-out/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Fri, 11 Jan 2013 15:12:58 +0000</pubDate>
				<category><![CDATA[Anouncements]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iOS 6]]></category>
		<category><![CDATA[Objective-C]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=765</guid>

					<description><![CDATA[Allright! I&#8217;ve had this dream, for like ages, to become a published book author. Now I&#8217;ve done it. iOS 6 Recipes is out. (Actually, it&#8217;s been out since late november but I&#8217;ve been so exhausted that I haven&#8217;t been able to muster the energy to blog about it.) iOS 6 Recipes is based on another [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Allright!</p>



<p>I&#8217;ve had this dream, for like ages, to become a published book author. Now I&#8217;ve done it. <a title="iOS 6 Recipes - A Problem-Solution Approach" href="http://rcm.amazon.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=wwwhansericco-20&amp;o=1&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=1430245999">iOS 6 Recipes</a> is out. (Actually, it&#8217;s been out since late november but I&#8217;ve been so exhausted that I haven&#8217;t been able to muster the energy to blog about it.)</p>



<p><iframe style="width: 120px; height: 240px;" src="http://rcm.amazon.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=wwwhansericco-20&amp;o=1&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=1430245999" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>



<p>iOS 6 Recipes is based on another book, iOS 5 Recipes, by Colin Francis and Shawn Grimes. My job was to upgrade that book with the new features of iOS 6, but as it turned out I had to rewrite most of the original content, keeping only the general structure and most of the old topics. I&#8217;m very proud of the result and although there are many ways in which it could still be improved, I believe I&#8217;ve accomplished the goal of producing a better book, valuable to its readers.</p>



<p>But I couldn&#8217;t have pulled this off if it wasn&#8217;t for the fantastic team at Apress, especially Anamika Panchoo (Coordinating Editor), <a href="https://www.apress.com/index.php/author/author/view/id/3565">Anselm Bradford</a> (Technical Rewiever), Douglas Pundick (Developmental Editor) and Linda Seifert (Copy Editor).</p>



<p>If you&#8217;ve read iOS 6 Recipes and want to share your thoughts, or ask me questions, feel free to contact me, either through the comments here or by emailing me (you&#8217;ll find my email address in the book).</p>



<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2013/01/11/ios-6-recipes-is-out/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>New XCode Tutorial: Turning View-based Into Navigation-based</title>
		<link>https://www.hans-eric.com/2011/09/30/new-xcode-tutorial-turning-view-based-into-navigation-based/</link>
					<comments>https://www.hans-eric.com/2011/09/30/new-xcode-tutorial-turning-view-based-into-navigation-based/#respond</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 21:46:28 +0000</pubDate>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[XCode 4]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=730</guid>

					<description><![CDATA[The other day I started a new iPhone project to create an app that I had been thinking about for quite some time now. I meant to build a Navigation-based app, but for some reason I used the general View-based application template to create my project. Nemas problemas &#8211; I thought &#8211; transforming it into [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The other day I started a new iPhone project to create an app that I had been thinking about for quite some time now. I meant to build a Navigation-based app, but for some reason I used the general View-based application template to create my project.</p>
<p>Nemas problemas &#8211; I thought &#8211; transforming it into a Navigation-based project should be simple enough. Call me stupid, or stubborn, but what seemed like an easy task took me the better part of a day to achieve; XCode can be very unintuitive some times, and the error messages not very helpful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Anyway, I thought I&#8217;d better put my achievement down in writing in case some of you out there will have the same need one day. Then maybe you&#8217;ll thank me for writing <a title="Tutorial: Turning View-based Into Navigation-based" href="https://www.hans-eric.com/share/tutorial-turning-a-view-based-into-a-navigation-based-project/">the Turning View-base into Navigation-based  tutorial</a>.</p>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/09/30/new-xcode-tutorial-turning-view-based-into-navigation-based/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>New Tutorial: Getting Started With UISpec on XCode 4</title>
		<link>https://www.hans-eric.com/2011/07/08/new-tutorial-getting-started-with-uispec-on-xcode-4/</link>
					<comments>https://www.hans-eric.com/2011/07/08/new-tutorial-getting-started-with-uispec-on-xcode-4/#respond</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Fri, 08 Jul 2011 20:17:31 +0000</pubDate>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[test-driven]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Acceptance Testing]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[UISpec]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=697</guid>

					<description><![CDATA[One of the most popular pages on this website is the tutorial that helps you getting started with UISpec; i guess there&#8217;s a great demand for acceptance testing frameworks on Objective-C. Anyway, I have just made a switch from XCode 3 to XCode 4, a huge improvement. A lot has changed in the user interface [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the most popular pages on this website is the tutorial that helps you getting started with UISpec; i guess there&#8217;s a great demand for acceptance testing frameworks on Objective-C.</p>
<p>Anyway, I have just made a switch from XCode 3 to XCode 4, a huge improvement. A lot has changed in the user interface so I decided to upgrade the UISpec tutorial, but kept the old one in case someone prefer the old IDE:</p>
<ul>
<li><a href="https://www.hans-eric.com/share/tutorial-getting-started-with-uispec-on-xcode-4/">Getting Started With UISpec on XCode 4</a></li>
<li><a href="https://www.hans-eric.com/share/getting-started-with-uispec/">Getting Started With UISpec on XCode 3</a></li>
</ul>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/07/08/new-tutorial-getting-started-with-uispec-on-xcode-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Incremental Development and Regression Testing Paper Released</title>
		<link>https://www.hans-eric.com/2011/05/17/incremental-development-and-regression-testing-paper-released/</link>
					<comments>https://www.hans-eric.com/2011/05/17/incremental-development-and-regression-testing-paper-released/#respond</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Tue, 17 May 2011 11:42:06 +0000</pubDate>
				<category><![CDATA[Anouncements]]></category>
		<category><![CDATA[software development]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=643</guid>

					<description><![CDATA[As you might know I wrote about the regression testing problem in The Swamp of Regression Testing. One of the commenters of that post, Ricky Clarkson, thought that the extensive use of the agile word got in the way of the underlying message. I’d love to see a copy of this article without “if you [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As you might know I wrote about the regression testing problem in <a href="https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/">The Swamp of Regression Testing</a>. One of the commenters of that post, Ricky Clarkson, thought that the extensive use of the <em>agile</em> word got in the way of the underlying message.</p>
<blockquote><p>I’d love to see a copy of this article without “if you don’t do X, you won’t be agile”, because where I work, agile isn’t a goal, but quality and quick turnaround is. If I passed this around, the word ‘agile’ would get in the way of an otherwise great message.</p></blockquote>
<p>That made so much sense that I decided to do just that. I wrote a new version, a complete rework of the original post, and published it as a separate document so that it can be easily passed around.</p>
<p>You find it under Shared Stuff on my website, or by following the below link.</p>
<p><a title="Incremental Development and Regression Testing, by Hans-Eric Grönlund" href="https://www.hans-eric.com/wp-content/uploads/2011/05/Incremental-development-and-regression-testing.pdf">Incremental Development and Regression Testing (PDF)</a></p>
<p>Please don&#8217;t hesitate to contact me if you have any feedback to share.</p>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/05/17/incremental-development-and-regression-testing-paper-released/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Automatic Acceptance Testing for iPhone</title>
		<link>https://www.hans-eric.com/2011/02/23/automatic-acceptance-testing-for-iphone/</link>
					<comments>https://www.hans-eric.com/2011/02/23/automatic-acceptance-testing-for-iphone/#respond</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 16:32:42 +0000</pubDate>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[test-driven]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=624</guid>

					<description><![CDATA[I&#8217;ve been playing around with XCode and iOS SDK lately, particularely with various alternatives for achieving automatic acceptance testing. (Which I belive is the only long-term solution to fight The Regression Testing problem.) One of the most promising solutions I&#8217;ve found is UISpec, modeled after Ruby&#8217;s mighty popular RSpec. Even though it still feels a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve been playing around with XCode and iOS SDK lately, particularely with various alternatives for achieving automatic acceptance testing. (Which I belive is the only long-term solution to fight <a title="The Swamp of Regression Testing" href="https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/">The Regression Testing problem</a>.)</p>
<p>One of the most promising solutions I&#8217;ve found is <a href="http://code.google.com/p/uispec/">UISpec</a>, modeled after Ruby&#8217;s mighty popular RSpec. Even though it still feels a bit rough cut, UISpec provides an easy way to write tests that invoke your application&#8217;s user interface; no recording, just plain Objective-C.</p>
<p>Anyway, in case you&#8217;re interested, I published a tutorial on how to set UISpec up for your project: <a href="https://www.hans-eric.com/share/getting-started-with-uispec/">Getting Started With UISpec</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/02/23/automatic-acceptance-testing-for-iphone/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Steve and Nat: Encapsulate Generics</title>
		<link>https://www.hans-eric.com/2011/02/21/steve-and-nat-encapsulate-generics/</link>
					<comments>https://www.hans-eric.com/2011/02/21/steve-and-nat-encapsulate-generics/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Mon, 21 Feb 2011 08:34:46 +0000</pubDate>
				<category><![CDATA[books]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=572</guid>

					<description><![CDATA[I&#8217;m reading Growing Object-Oriented Software, Guided by Tests, by Steve Freeman and Nat Pryce. I was happy to find that the authors share a similar view on constructed generic types as I do. Our rule of thumb is that we try to limit passing around types with generics [&#8230;]. Particularly when applied to collections, we view [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m reading <a href="http://www.amazon.com/gp/product/0321503627?ie=UTF8&amp;tag=wwwhansericco-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321503627">Growing Object-Oriented Software, Guided by Tests</a><img decoding="async" style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=wwwhansericco-20&amp;l=as2&amp;o=1&amp;a=0321503627" border="0" alt="" width="1" height="1" />, by Steve Freeman and Nat Pryce. I was happy to find that the authors share a similar view on constructed generic types as I do.</p>
<blockquote><p>Our rule of thumb is that we try to limit passing around types with generics [&#8230;]. Particularly when applied to collections, we view it as a form of duplication. It&#8217;s a hint that there&#8217;s a domain concept that should be extracted into a type.</p></blockquote>
<p>A less blunt way of saying what I tried to say in <a title="Generic Types are Litter" href="https://www.hans-eric.com/2010/07/28/generics-are-litter/">my own post</a>.</p>
<p>If you&#8217;re interested in the book I can strongly recommend it. Although I&#8217;m only half-way through it I can already tell it&#8217;s the best TDD book I have read so far. I&#8217;ll have a brief review up in a coming post.</p>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/02/21/steve-and-nat-encapsulate-generics/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>The First Rule of Holes</title>
		<link>https://www.hans-eric.com/2011/01/26/the-first-rule-of-holes/</link>
					<comments>https://www.hans-eric.com/2011/01/26/the-first-rule-of-holes/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Wed, 26 Jan 2011 15:44:06 +0000</pubDate>
				<category><![CDATA[learning]]></category>
		<category><![CDATA[project management]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=544</guid>

					<description><![CDATA[At some point someone made a promise. Now the team is in a bad position and struggling hard to meet the deadlines of the original plan. I&#8217;ve been in that position more than once, and as a Scrum Master I have used the same strategy: Working with the customer to lower expectations and make the plan more [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/Digging.bmp"><img decoding="async" title="Digging" src="https://www.hans-eric.com/wp-content/uploads/2011/01/Digging.bmp" alt="We don't have time for reevaluation. Keep digging!" /></a></p>
<p>At some point someone made a promise. Now the team is in a bad position and struggling hard to meet the deadlines of the original plan.</p>
<p>I&#8217;ve been in that position more than once, and as a Scrum Master I have used the same strategy:</p>
<ol>
<li>Working with the customer to <a title="The Essence of Project Management" href="https://www.hans-eric.com/2010/07/20/the-essence-of-project-management/">lower expectations</a> and make the plan more aligned with reality.</li>
<li>Find more time for the team to do its work.</li>
</ol>
<p>The second part would make me cancel everything not immediately helping the team accomplishing its short-term goals. The retrospective meetings were always the first thing that went out the window, and I felt like I was helping the team by doing it.</p>
<p>That was before the first rule of holes was brought to my attention (<a href="http://www.crisp.se/henrik.kniberg">by Henrik Kniberg</a>).</p>
<blockquote><p>The first rule of holes: When you&#8217;re in one stop digging.</p></blockquote>
<p>That wonderful quote by <a href="http://en.wikipedia.org/wiki/Molly_Ivins">Molly Ivins</a> really got me thinking. To bring a derailed train back on track, the solution is not to make the engines run faster. Instead we need to make a careful evaluation of the situation, and find solutions that will help us achieve the end goal of getting the passengers and cargo reach its destination on time.</p>
<p>In software development terms, when the going gets tough, we need our retrospectives the most.</p>
<p>Another way I&#8217;ve violated the first rule of holes is the thing I wrote about in <a title="The Swamp of Regression Testing" href="https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/">my previous post</a>. Although I know that automated tests is one of the best ways to increase productivity, I came up with all sorts of excuses why &#8220;it wasn&#8217;t for us&#8221;. So, I&#8217;ve let my teams dig deeper holes and making a bad situation worse.</p>
<p><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/Digging.bmp"></a></p>
<p><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/diggingtochina.png"></a></p>
<p>Yet another common violation is the building up of technical debt. We&#8217;re so busy digging for new features that we forget that we have to be able to ascend from the pit. We need to stop digging and <a title="The Boy Scout Rule" href="https://www.hans-eric.com/2010/07/26/the-boy-scout-rule/">clean the small messes</a> before they become drainers of effort.</p>
<p>What holes have you created or ended up in? What did you do about it? I&#8217;d love to hear your stories.</p>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/01/26/the-first-rule-of-holes/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>The Swamp of Regression Testing</title>
		<link>https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/</link>
					<comments>https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/#comments</comments>
		
		<dc:creator><![CDATA[Hans-Eric]]></dc:creator>
		<pubDate>Mon, 17 Jan 2011 16:11:08 +0000</pubDate>
				<category><![CDATA[opinion]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[test-driven]]></category>
		<category><![CDATA[testing]]></category>
		<guid isPermaLink="false">https://www.hans-eric.com/?p=518</guid>

					<description><![CDATA[Have you ever read a call for automation of acceptance testing? Did you find the idea really compelling but then came to the conclusion that it was too steep a mountain for your team to climb, that you weren&#8217;t in a position to be able to make it happen? Maybe you gave it a half-hearted [&#8230;]]]></description>
										<content:encoded><![CDATA[<div class="mceTemp">Have you ever read a call for automation of acceptance testing? Did you find the idea really compelling but then came to the conclusion that it was too steep a mountain for your team to climb, that you weren&#8217;t in a position to be able to make it happen? Maybe you gave it a half-hearted try that you were forced to abandon when the team was pressured to deliver &#8220;business value&#8221;? Then chances are, like me, you heard but didn&#8217;t really listen.</div>
<div class="mceTemp"></div>
<div class="mceTemp">You <em>must</em> automate your acceptance testing!</div>
<p>Why? Because otherwise you&#8217;re bound to get bogged down by <em>the swamp of regression testing</em>.</p>
<p><strong>Regression Testing in Incremental Development</strong></p>
<p>Suppose we&#8217;re building a system using a traditional method; We design it, build it and then test it &#8211; in that order. For the sake of simplicity assume that the effort of acceptance testing the system is illustrated by the box below.</p>
<div class="mceTemp">
<p><div id="attachment_521" style="width: 175px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/1_specified_system.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-521" class="size-full wp-image-521  " style="margin-top: 12px; margin-bottom: 12px;" title="A Specified System" src="https://www.hans-eric.com/wp-content/uploads/2011/01/1_specified_system.png" alt="Box depicting a specified system" width="165" height="355" /></a><p id="caption-attachment-521" class="wp-caption-text">The amount of acceptance testing using a traditional approach</p></div></p>
</div>
<p>Now, suppose we&#8217;re creating the same system using an agile approach; Instead of building it all in one chunk we develop the system incrementally, for instance in three iterations.</p>
<p><div id="attachment_524" style="width: 175px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/3_incremental_approach.png"><img decoding="async" aria-describedby="caption-attachment-524" class="size-full wp-image-524 " style="margin-top: 12px; margin-bottom: 12px;" title="Incremental Approach" src="https://www.hans-eric.com/wp-content/uploads/2011/01/3_incremental_approach.png" alt="The system is divided into parts (in this example three parts: A, B and C)." width="165" height="357" /></a><p id="caption-attachment-524" class="wp-caption-text">An agile approach. The system is developed in increments.</p></div></p>
<p><div id="attachment_533" style="width: 529px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/iteration_1_2_3.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-533" class="size-full wp-image-533 " style="margin-top: 12px; margin-bottom: 12px;" title="Increments 1, 2 &amp; 3" src="https://www.hans-eric.com/wp-content/uploads/2011/01/iteration_1_2_3.png" alt="" width="519" height="414" /></a><p id="caption-attachment-533" class="wp-caption-text">New functionality is added with each iteration</p></div></p>
<p><strong>Potential Releasability</strong></p>
<p>Now, since we&#8217;re &#8220;agile&#8221;, acceptance testing the new functionality after each iteration is not enough. To ensure &#8220;potential releasability&#8221; for our system increments, we also need to check all previously added functionality so that we didn&#8217;t accidentally break anything we&#8217;ve already built. Test people call this regression testing.</p>
<p>Can you spot the problem? Incremental development requires more testing. A lot more testing. For our three iteration big  example, twice as much testing.</p>
<div class="mceTemp">
<div class="mceTemp">
<p><div id="attachment_534" style="width: 362px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/8_amount_of_testing_agile1.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-534" class="size-full wp-image-534 " style="margin-top: 12px; margin-bottom: 12px;" title="8_amount_of_testing_agile" src="https://www.hans-eric.com/wp-content/uploads/2011/01/8_amount_of_testing_agile1.png" alt="" width="352" height="694" /></a><p id="caption-attachment-534" class="wp-caption-text">The theoretical amount of acceptance testing using an agile approach and three iterations, is twice as much as in Waterfall</p></div></p>
</div>
</div>
<p>Unfortunately, it&#8217;s even worse than that. The amount of acceptance testing increases exponentially with the number of increments. Five iterations requires three times the amount of testing, nine requires five times, and so on.</p>
<p><div id="attachment_522" style="width: 493px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/9_amount_of_testing_agile_graph.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-522" class="size-full wp-image-522 " style="margin-top: 12px; margin-bottom: 12px;" title="9_amount_of_testing_agile_graph" src="https://www.hans-eric.com/wp-content/uploads/2011/01/9_amount_of_testing_agile_graph.png" alt="" width="483" height="291" /></a><p id="caption-attachment-522" class="wp-caption-text">The amount of acceptance testing increase rapidly with the number of increments.</p></div></p>
<p>This is the reason many agile teams lose velocity as they go, either by yielding to an increasing burden of test (if they do what they should) or by spending an increasing amount of time fixing bugs that cost more to fix since they&#8217;re discovered late. (Which is the symptom of an inadequately tested system.)</p>
<p><strong>A Negative Force</strong></p>
<p>Of course, this heavily simplified model of acceptance testing is full of flaws. For example:</p>
<ul>
<li>The nature of acceptance testing in a Waterfall method is very different from the acceptance testing in agile. (One might say though that the Waterfall hides behind a false assumption (that all will go well) which looks good in plans but becomes ugly in reality).</li>
<li>One can&#8217;t compare initial acceptance testing of newly implemented features, with regression testing of the same features. The former is real testing, while the second is more like checking. (By the way, read this interesting discussion on the difference of testing and checking: <a title="Ron Jeffries: Which End of the Horse" href="http://xprogramming.com/articles/which-end-of-the-horse/">Which end of the horse</a>.)</li>
</ul>
<p><strong>Still, I think it&#8217;s safe to say</strong> that there is a force working against us, a force that gets greater with time. The burden of regression testing challenges any team doing incremental development.</p>
<p>So, should we drop the whole agile thing and run for the nearest waterfall? Of course not! We still want to build the right system. And finding that out last is not an option.</p>
<p><div id="attachment_523" style="width: 325px" class="wp-caption alignnone"><a href="https://www.hans-eric.com/wp-content/uploads/2011/01/2_wanted_system.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-523" class="size-full wp-image-523 " style="margin-top: 12px; margin-bottom: 12px;" title="2_wanted_system" src="https://www.hans-eric.com/wp-content/uploads/2011/01/2_wanted_system.png" alt="" width="315" height="384" /></a><p id="caption-attachment-523" class="wp-caption-text">The system we want is never the system we thought we wanted.</p></div></p>
<p>OK, but can&#8217;t we just skip the regression testing? In practice, this is what many teams do. But it&#8217;s not a good idea. Because around The Swamp of Regression Testing lies The Forest of Poor Quality. We don&#8217;t want to go there. It&#8217;s an unpleasant and unpredictable place to be.</p>
<p>We really need to face the swamp. Otherwise, how can we be potentially releasable?</p>
<p>The only real solution is to automate testing. And I&#8217;m not talking about unit testing here. Unit testing is great but has a different purpose: Unit-testing verifies that the code does what you designed it to do. Acceptance testing on the other hand verifies that our code does what the customer (or product owner, please use your favorite word for the one that pays for the stuff you build) asked for. That&#8217;s what we need to test to achieve potential releasability.</p>
<p>So, get out there and find a way to automate your acceptance testing. Because if you don&#8217;t, you can&#8217;t be agile.</p>
<p>Cheers!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hans-eric.com/2011/01/17/the-swamp-of-regression-testing/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
			</item>
	</channel>
</rss>
