-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1779 from qdraw/feature/202410_architecturetest
Add architecture test
- Loading branch information
Showing
6 changed files
with
479 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "Testing", | ||
"position": 12, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Overview of Testing in the Platform" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
documentation/docs/developer-guide/testing/architecture-test.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Architecture Test Documentation | ||
|
||
## Overview | ||
|
||
The `ArchitectureTest.cs` file contains automated tests to ensure that the project's architecture | ||
adheres to specific guidelines. These guidelines are based on the Sitecore Helix principles, which | ||
help maintain a clean and scalable architecture over time. | ||
|
||
## Key Concepts | ||
|
||
### Fitness Functions | ||
|
||
Fitness functions are tests that confirm whether a particular characteristic of the solution's | ||
architecture is maintained over time. These tests help ensure that the architecture remains | ||
consistent and adheres to predefined rules. | ||
|
||
### Helix Principles | ||
|
||
The Helix principles define a set of guidelines for structuring projects within a solution. The key | ||
rules enforced by these tests are: | ||
|
||
- **Foundation projects** should only reference other Foundation projects. | ||
- **Feature projects** should only reference Foundation projects. | ||
- **Project projects** should only reference Foundation or Feature projects. | ||
|
||
## Test Class: `TheSolutionShould` | ||
|
||
### Purpose | ||
|
||
The `TheSolutionShould` class contains tests that validate the project reference structure within | ||
the solution. It ensures that the inter-project references comply with the Helix principles. | ||
|
||
### Key Methods | ||
|
||
#### `ContainNoHelixInvalidProjectReferences` | ||
|
||
This test method verifies that there are no invalid project references within the solution. It | ||
performs the following steps: | ||
|
||
1. **Arrange**: Retrieves a list of projects and their references. | ||
2. **Act**: Reviews the project list for invalid references. | ||
3. **Assert**: Checks if any invalid references are found and asserts that there should be none. | ||
|
||
#### `GetProjectsWithReferences` | ||
|
||
This method retrieves a dictionary of projects and their references from the solution file. | ||
|
||
#### `GetSolutionFilePath` | ||
|
||
This method locates the solution file path based on the base directory. | ||
|
||
#### `GetProjectsFromSolutionFileContents` | ||
|
||
This method extracts project references from the solution file contents using a regular expression. | ||
|
||
#### `GetReferencedProjects` | ||
|
||
This method retrieves the referenced projects from a given project file. | ||
|
||
#### `GetInvalidReferences` | ||
|
||
This method identifies invalid references for a given project based on the specified invalid layers. | ||
|
||
#### `AssertLayerReferences` | ||
|
||
This method asserts that there are no invalid references for a given layer. | ||
|
||
## Known Issues | ||
|
||
- The `starsky.feature.trash` project references the `starsky.feature.metaupdate` project, which is | ||
a known issue and should be refactored in the future. | ||
|
||
## References | ||
|
||
- [Microservices and Evolutionary Architecture](https://www.thoughtworks.com/insights/blog/microservices-evolutionary-architecture) | ||
- [Building Evolutionary Architectures](http://shop.oreilly.com/product/0636920080237.do) | ||
- [Sitecore Helix Documentation](http://helix.sitecore.net/introduction/index.html) | ||
|
||
--- | ||
|
||
This documentation provides an overview of the purpose and functionality of the | ||
`ArchitectureTest.cs` file, along with explanations of key concepts and methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Unit tests | ||
|
||
In this project, we use unit tests to verify the correctness of individual components | ||
in. | ||
|
||
- Language: The unit tests are written in C#. | ||
- Framework: The tests use a testing framework such as MSTest. | ||
- Structure: The tests are organized to cover various layers and components of the application, | ||
ensuring comprehensive coverage. | ||
- Test Cases: Each test case is designed to validate specific functionality, edge cases, and error | ||
conditions. | ||
- Automation: The tests can be run automatically as part of a continuous integration (CI) pipeline to | ||
ensure that new changes do not introduce regressions. | ||
|
||
## Here are some best practices for writing unit tests: | ||
|
||
1. **Write Independent Tests**: Each test should be independent and not rely on the outcome of other | ||
tests. | ||
2. **Use Descriptive Names**: Test method names should clearly describe what is being tested and the | ||
expected outcome. | ||
3. **Follow the AAA Pattern**: Arrange, Act, Assert. First, set up the test data and environment ( | ||
Arrange), then execute the code being tested (Act), and finally verify the result (Assert). | ||
4. **Test One Thing at a Time**: Each test should focus on a single piece of functionality or | ||
behavior. | ||
5. **Keep Tests Small and Focused**: Small, focused tests are easier to understand, maintain, and | ||
debug. | ||
6. **Use Mocks and Stubs**: We manually mock services, at the moment we don't use a library for this. | ||
7. **Ensure Tests are Repeatable**: Tests should produce the same results every time they are run, | ||
regardless of the environment or order of execution. | ||
8. **Run Tests Frequently**: Integrate tests into the development process and run them frequently to | ||
catch issues early. | ||
9. **Test Edge Cases and Error Conditions**: Ensure that tests cover edge cases and potential error | ||
conditions. | ||
10. **Maintain Test Code Quality**: Apply the same standards to test code as you do to production | ||
code, including readability, maintainability, and adherence to coding standards. | ||
|
||
By following these best practices, you can create effective and reliable unit tests that help | ||
maintain the quality of your codebase. |
Oops, something went wrong.