Skip to content

It would be nice to [have an option to] provide test source code snippet on failure #265

@vors

Description

@vors

I often find myself in a situation, when I cannot express my intention with a pester test.
By express I mean: person who see failed test results should understand what's the matter of failure with the least possible actions.

For example, let's take some binary condition.

Let's say these are my functions:

function Get-SmartFoo() {
    sleep 2
    'foo'
}

function Get-DumbFoo() {
    sleep 1
    'foo'
}

I want to express: Get-SmartFoo should work faster then Get-DumbFoo (which is currently not true).
Here is what I can write:

Describe 'SmartFoo' {

    It 'Return string foo' {
        Get-SmartFoo | Should be 'foo'
    }

    It 'faster then DumbFoo' {
        $smartFooTime = (Measure-Command { Get-SmartFoo }).TotalSeconds
        $dumbFooTime = (Measure-Command { Get-DumbFoo }).TotalSeconds
        $smartFooTime -lt $dumbFooTime | Should Be $true
    }
}

image

Imagine, you didn't touch test code for a while. Probably, you will go to the source and find the line 20 to see what exactly the code does.

I would prefer to see a code snippet from the failure immediately in the test results.
For instance

image

With this knowledge, I can write my tests much wiser. I would use meaningful variable names, to provide a context about the failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions