< Back

Context

Wed Jan 30, 2019 5:56 pm

NAME Context



SYNOPSIS

Provides logical grouping of It blocks within a single Describe block. Any Mocks defined

inside a Context are removed at the end of the Context scope, as are any files or folders

added to the TestDrive during the Context block's execution. Any BeforeEach or AfterEach

blocks defined inside a Context also only apply to tests within that Context .





SYNTAX

Context [-Name] <String> [[-Fixture] <ScriptBlock>] [<CommonParameters>]





DESCRIPTION





PARAMETERS

-Name <String>

The name of the Context. This is a phrase describing a set of tests within a describe.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Fixture <ScriptBlock>

Script that is executed. This may include setup specific to the context and one or more It

blocks that validate the expected outcomes.



Required? false

Position? 2

Default value $(Throw "No test script block is provided. (Have you put the open curly brace on the next line?)")

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>function Add-Numbers($a, $b) {



return $a + $b

}



Describe "Add-Numbers" {



Context "when root does not exist" {

It "..." { ... }

}



Context "when root does exist" {

It "..." { ... }

It "..." { ... }

It "..." { ... }

}

}











RELATED LINKS

Describe

Excel: Text to columns: extract data and add delimiters

BeforeEach

AfterEach

about_Should

about_Mocking

about_TestDrive