Skip to content

Commit

Permalink
Merge pull request #2 from webnativedev/develop
Browse files Browse the repository at this point in the history
Mostly unit tests and coverage
  • Loading branch information
webnativedev committed Jul 20, 2023
2 parents bc0afc1 + c814a1e commit 44ee66b
Show file tree
Hide file tree
Showing 49 changed files with 1,936 additions and 368 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,23 @@ jobs:
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
- name: Show folder structure
run: |
ls -al
ls -al source
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Restore dependencies
run: dotnet restore source/SINUS.sln -v:n

- name: Build and analyze
run: |
dotnet build --configuration DEBUG --no-restore --no-incremental source/SINUS.sln -v:n
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ jobs:
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Restore dependencies
run: dotnet restore source\sinus.sln -v:n
- name: Debug-ShowDir-PreBuild
shell: powershell
run: Get-ChildItem .
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"webnativedev_SINUS" /o:"webnativedev" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build --configuration DEBUG --no-incremental source\sinus.sln -v:n
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
.\.sonar\scanner\dotnet-sonarscanner begin /k:"webnativedev_SINUS" /o:"webnativedev" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vstest.reportsPaths=TestResults/*.trx /d:sonar.cs.opencover.reportsPaths=TestResults/*/coverage.opencover.xml
dotnet build --configuration DEBUG --no-restore --no-incremental source\sinus.sln -v:n
dotnet test source\sinus.sln --no-build --no-restore --collect:"XPlat Code Coverage;Format=json,lcov,cobertura,opencover" --results-directory TestResults/ --logger "trx;LogFileName=coverage.trx" --logger:"console;verbosity=detailed" --filter "TestCategory!=external"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: Debug-ShowDir-PostBuild
shell: powershell
run: |
Get-ChildItem .
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ in the industry of software development.
* Opinionated: SINUS can be your one-stop-shop library for testing
based on MS-Test in a nice BDT API, but consider that you will introduce also
some dependencies to libraries that need to considered (e.g.: Selenium).
* Opinionated: track code coverage automatically to be confident about the amount of tests.
Herefore use CI/CD analysis and quality gates, but consider also local analysis.
https://github.com/danielpalme/ReportGenerator
* create some service tests.
* Opinionated: SINUS will help you with that task as well, but it might be
beneficial for the overall process to create a small UI to test. A lot
Expand All @@ -68,21 +71,40 @@ Quality criterias are:
* maintainable
* trustworthy

Consider:

* standard flow (positive cases)
* edge cases
* failing flows (negative cases)

(see equivalence partitioning)

### Unit Tests

Unit tests should be "FIRST" (fast, isolated/independent, repeatable, self-validating, thorough).

Do not test:

* bootstrap code (container registration, initialization)
* configuration (constants, enums, readonly fields)
* model classes and data transfer objects (DTO)
* language / framework features of the programming environment
* functions that directly return variables
* facades without any logic
* private methods
* Finalizers (especially in combination with IDisposable pattern implementation)
* exception messages and log messages

To sum it up, we are testing execution logic that can be called from outside of the unit without depending on the internal setup and implementation.

## Integration Tests

By using a custom WebApplicationFactory we can execute isolated tests in-memory.
This mode helps in REST-based tests, but is not compatible with Selenium tests requiring a publicly available service.

Hereby we see methods that instrument the code that is checked by the integration test to be able to evaluate the code coverage.
https://learn.microsoft.com/en-us/visualstudio/test/microsoft-code-coverage-console-tool?view=vs-2022

## Getting Started

* Create a test project
Expand All @@ -101,6 +123,7 @@ To sum it up, we are testing execution logic that can be called from outside of
* With the Given part (use intelliSense) you can spin-up a browser and optionally a System-Under-Test (SUT) in-memory or public (meaning reachable via network outside the test).
* use public SUT configuration for UI tests, because the web driver spawns outside the unit test in a separate process.
* consider to use components for mocking / test doubles
* Opinionated: use Moq for mocking
* With the When part (use intelliSense) you can perform the main action and here no action means a prepared test, that can not yet be evaluated properly.
* With the Then part (use intelliSense) you can perform checks on the action.
* Consider to install an Assertion Library helping you writing more meaningful assertions.
Expand All @@ -110,3 +133,5 @@ To sum it up, we are testing execution logic that can be called from outside of
* Opinionated: Call it explicitly. It allows you to impelement the method as expression body via ```=>```.
* Consider using StyleCop (also for the test-project)
* Opinionated: remove CS1591, SA1600 for tests to remove the necessary XML documentation which is already covered via method name and description fields of SINUS.
* Consider using a memory leak analysis tool or directly a supporting nuget package.
* (no own experience yet:) https://www.jetbrains.com/dotmemory/unit/ | https://www.nuget.org/packages/JetBrains.DotMemoryUnit/
12 changes: 12 additions & 0 deletions source/.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
</CodeCoverage>
</Configuration>
</DataCollector>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>json,cobertura,lcov,teamcity,opencover</Format>
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
<SingleHit>false</SingleHit>
<UseSourceLink>true</UseSourceLink>
<IncludeTestAssembly>true</IncludeTestAssembly>
<SkipAutoProps>true</SkipAutoProps>
<DeterministicReport>false</DeterministicReport>
<ExcludeAssembliesWithoutSources>MissingAll,MissingAny,None</ExcludeAssembliesWithoutSources>
</Configuration>
</DataCollector>

</DataCollectors>
</DataCollectionRunSettings>
Expand Down

0 comments on commit 44ee66b

Please sign in to comment.