Open sydkar opened 9 months ago
what version of bicep cli do I need for the test command?
And the asserts would be more useful if they could be chained from the object labeled "test". Filling them into my existing bicep files isn't easy.
Are there any updates on this feature?
@oliverlabs This project has been put on hold for the moment unfortunately. We will update this issue when we pick it back up!
any updates?
Any updates? This would be a great feature to have!
Bicep Experimental Test Framework
Introduction
We began prototyping experimental test features early in summer 2023, and we’ve been encouraged by the level of customer interest in the project. While we are still early in exploring what the future of testing looks like in Bicep, we are eager to get early feedback. If you choose to enable the feature, beware the functionality is still experimental and subject to change at any time.
Read the full proposal for the testing framework here.
How to get started with experimental test framework
assertions
andtestFramework
experimental feature flags in abicepconfig.json
file. Both feature flags must be enabled for expected functionality..bicep
file to author your tests, eg.tests.bicep
. This must be a separate file from the.bicep
template you want to test. Author a test block with the newtest
keyword, referencing a.bicep
template you would like to test on the client-side (without deploying).assert
statements to validate parameters, variables, and resource names within the .bicep template file you would like to test that you referenced in your test blocks.bicep test <filepath_to_test_file>
to runtest
blocks and their correspondingassert
statements without deploying.1. Enable experimental features
Enable testing experimental features in
bicepconfig.json
bicepconfig.json
file within your Bicep project repobicepconfig.json
, defineexperimentalFeaturesEnabled
and settestFramework: true
andassertions: true
2. Test blocks
test
block syntax:test
keywordtestMain
)‘main.bicep’
)params
object mocking parameter values from the Bicep file (eg.params: {env: 'prod'}
)Example:
Lmitations:
3. Assert statements
assert
statement syntax:assert
keywordappName
)= contains(appServiceApp.name, "${env}"
)assert
statements can be any boolean expression that references parameters, variables, or resource names. These boolean expressions can include Bicep functions such as "contains()", "length()", etc.Examples:
Limitations: