TcHaxx.Snappy.CLI
0.0.5
See the version list below for details.
dotnet tool install --global TcHaxx.Snappy.CLI --version 0.0.5
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local TcHaxx.Snappy.CLI --version 0.0.5
#tool dotnet:?package=TcHaxx.Snappy.CLI&version=0.0.5
nuke :add-package TcHaxx.Snappy.CLI --version 0.0.5
🚧 WIP
snappy
Snappy is a Snapshot Testing framework, like Verify, designed for TwinCAT 3.
During the assertion phase, Snappy performs the following steps:
- It serializes the test result and saves it in a file that corresponds to the test-suite and test name.
- In subsequent test executions, it re-serializes the result and compares it to the existing file.
- If the two snapshots do not match, the test fails.
This discrepancy could indicate either an unexpected change or the need to update the reference snapshot to reflect the new result - The validated files can the be added to source control.
Example using TcUnit
FUNCTION_BLOCK FB_TcUnitExample EXTENDS FB_TestSuite
VAR
hr : HRESULT;
fbTcUnitAdapter : FB_TcUnitAdapter;
stActual : ST_DemoDataType;
{attribute 'analysis' := '-33'}
stResult : ST_VerificationResult;
END_VAR
TEST('Test some stuff with TcHaxx.Snappy');
// ARRANGE
// ACT
stActual := F_CreateDemoData();
// ASSERT
hr := fbTcUnitAdapter.Verify(anyArg:= stActual);
IF NOT PENDING(hr) THEN
TEST_FINISHED_NAMED('Test some stuff with TcHaxx.Snappy');
END_IF;
Find more examples in the
examples
PLC project.
Install
Snappy consists of two parts:
- A dotnet CLI tool, called
TcHaxx.Snappy.CLI
, - and the TwinCAT library
snappy
.
Prerequisites
- rplc library is installed.
- Verify - Supported Tool is installed.
TcHaxx.Snappy.CLI
To install the CLI tool execute following command:
dotnet tool install -g TcHaxx.Snappy.CLI
Update
To update to the latest version from Nuget, run:
dotnet tool update -g TcHaxx.Snappy.CLI
Uninstall
dotnet tool uninstall -g TcHaxx.Snappy.CLI
snappy.library
Download latest releases, either snappy.library
and/or snappy.compiled-library
and install.
Usage
Before any tests are being run, TcHaxx.Snappy.CLI
hast to be started, prior.
Run manually via dotnet tools or TwinCAT deployment.
dotnet tools
TcHaxx.Snappy.Verify verify [OPTIONS]
TwinCAT 3 PLC Deployment
To automatically start TcHaxx.Snappy.CLI
you may want to add following event to your PLC project properties:
Event | Command Type | Parameter 1 | Parameter 2 |
---|---|---|---|
Activate Configuration | Execute | cmd /c start TcHaxx.Snappy.CLI verify -d \"%SOLUTIONPATH%.snappy-verified\" |
Source control: Received and Verified files
When dealing with source control, consider the following guidelines for handling Received and Verified files:
Exclusion:
- Exclude all files with the pattern
*.received.*
from source control. - To achieve this, add the following line to your
.gitignore
file:*.received.*
- Exclude all files with the pattern
Commitment:
- On the other hand, commit all files with the pattern
*.verified.*
to source control.
- On the other hand, commit all files with the pattern
See Verify/README
Acknowledgments
- TcUnit - A unit testing framework for Beckhoff's TwinCAT 3
- CommandLineParser - A command line parsing library for .NET applications.
- Verify - A library used for snapshot testing.
- Serilog - A logging library for .NET applications.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
This package has no dependencies.