bicep
bicep copied to clipboard
Bicep Experimental Test Framework
Bicep Experimental Test Framework
Owner: Emily Redmond
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
- Enable
assertionsandtestFrameworkexperimental feature flags in abicepconfig.jsonfile. Both feature flags must be enabled for expected functionality. - Create a new
.bicepfile to author your tests, eg.tests.bicep. This must be a separate file from the.biceptemplate you want to test. Author a test block with the newtestkeyword, referencing a.biceptemplate you would like to test on the client-side (without deploying). - Author
assertstatements to validate parameters, variables, and resource names within the .bicep template file you would like to test that you referenced in your test blocks. - In your CLI, run the command
bicep test <filepath_to_test_file>to runtestblocks and their correspondingassertstatements without deploying.
1. Enable experimental features
Enable testing experimental features in bicepconfig.json
- Create
bicepconfig.jsonfile within your Bicep project repo

- Within
bicepconfig.json, defineexperimentalFeaturesEnabledand settestFramework: trueandassertions: true

2. Test blocks
test block syntax:
testkeyword- Name of test block (eg.
testMain) - Reference to Bicep file to test (eg.
‘main.bicep’) paramsobject mocking parameter values from the Bicep file (eg.params: {env: 'prod'})
Example:

Lmitations:
- You must pass in a parameter object, you cannot reference an existing parameter file currently
- Test blocks must be in a separate file from the .bicep template you want to test
- Test result output summary is not standardized
3. Assert statements
assert statement syntax:
assertkeyword- Name of assert statement (eg.
appName) - equals boolean validation expression (eg.
= 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:
- You can only assert on parameters, variables, and resource names with current functionality
- You cannot assert on resource size, location, or other propreties yet as these depend on runtime deployment functionality
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!
Hi @stephaniezyen , is there any update on this exciting feature, any plans to release it?
Hi Folks - no updates. It's something we are eager to put more energy into, but do not have the ability to prioritize it at the moment.