Тёмный

Test Your Code Quality with Pester and PSScriptAnalyzer - Leo Visser - PSConfEU 2023 

PowerShell Conference EU
Подписаться 5 тыс.
Просмотров 660
50% 1

In this episode, I, Leo Visser, a Cloud Consultant at OGD ICT Diensten in the Netherlands, dive into the topic of code quality. I explain that code quality focuses on how well the code is written, including factors such as code formatting, unused code, and adherence to coding standards. To test code quality, I highlight the use of two tools: PS Script Analyzer and Pester.
PS Script Analyzer is a linting tool that provides a checklist of code issues and warnings. I demonstrate its usage on a sample script, showcasing potential problems like the use of "write-host" and trailing white space. Although these issues may not affect code functionality significantly, it's good practice to avoid them.
Moving on to Pester, it is a testing framework that allows us to execute tests on our code. Whether it's unit testing or integration testing, Pester provides a way to trigger commands or scripts, compare outputs, and generate test reports.
Incorporating PS Script Analyzer into our testing workflow ensures that any errors or warnings are identified before code is pushed to production. This can be done manually using the "Invoke-ScriptAnalyzer" command or through automated processes like VS Code extensions.
During the conversation, we discuss using Pester to create tests for script analyzer. We cover the naming convention for Pester tests and how to handle them in VS Code. We explain the structure of a Pester test using "describe" and "it" statements.
To make it easier to identify problematic files, I present an advanced version of the test. This version gathers all the rules and severities of script analyzer and creates separate tests for each rule. The "invoke script analyzer" command is used for each rule, checking for outcomes. If there are outcomes, they are appended to a string. Running the advanced Pester test provides detailed information on which rules failed and in which files, saving time in issue identification.
We also discuss filtering test results by severity using Pester tags. By using tags, we can choose to display only warnings or errors and exclude information outcomes.
Another approach we explore is working with exemptions when using Script Analyzer to test scripts. I demonstrate how specific errors can be suppressed using the "diagnostic code analyze suppressed message attribute" line of code. This allows us to accept certain errors for specific files, generating self-documenting code.
Integrating this testing process into CICD pipelines using Azure DevOps or GitHub Actions is the next step. I explain how to set up a pipeline that triggers the test file, showcasing the YAML file used for the pipeline. I mention the option to publish a test report in Azure DevOps, providing visual graphs of successful and failed tests.
Additionally, we discuss how the script analyzer tool integrates with Git systems like GitHub and Azure DevOps, enabling pull request validation. Setting up branch policies and build validation ensures that the pipeline runs on the code before proceeding, automatically checking for common issues. I touch on the possibility of sending pipeline output back to the test plan.
To enforce running tests before pushing to a remote repository, I suggest using Git hooks or setting up pipelines to trigger automatically and notify the developer if the pipeline fails.
In conclusion, I express gratitude to the audience for listening and encourage them to reach out with any further questions or concerns.
Chapters:
00:00:00 Test Your Code Quality with Pester and PSScriptAnalyzer - Leo Visser - PSConfEU 2023
00:00:07 Introduction and Acknowledgment of Sponsors
00:01:51 Definition of Code Quality and Introduction to PS Script Analyzer
00:03:19 PS Script Analyzer as a Linting Tool for PowerShell
00:04:29 Split in PowerShell Community on Using Right Host
00:06:02 Importance of Removing Trailing White Space in Code
00:06:24 Introduction to Pester Testing Framework
00:08:03 Incorporating PSScriptAnalyzer into …

Наука

Опубликовано:

 

18 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
Далее
Get to know Bruce Payette - PSConfEU 2024
57:33
Bike Vs Tricycle Fast Challenge
00:43
Просмотров 19 млн
Dora was kidnapped and then… 😨 #shorts
00:18
Просмотров 2,9 млн
How to Think like a Programmer
1:45:15
Просмотров 280
Tesla's Self-Driving Is Going Global
19:43
Просмотров 38 тыс.
AMD Just FIXED Ryzen 9000!
9:20
Просмотров 6 тыс.
Apple October Event LEAKS - 7 NEW Devices are COMING!
10:20
Get to know Steven Bucher - PSConfEU 2024
34:44
Всё, Nintendo Switch 2 СЛИЛИ
11:01
Просмотров 27 тыс.
ДЖУНГЛИ В КОМПЕ..
1:00
Просмотров 290 тыс.
ДЖУНГЛИ В КОМПЕ..
1:00
Просмотров 290 тыс.
😍Вышла iOS 18! ЛУЧШИЕ Фишки🔥
0:54