Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/approvals/approvaltests.dart.starterproject
Starter Project for Approval Tests implementation in Dart
https://github.com/approvals/approvaltests.dart.starterproject
approval-tests approvals approvals-dart dart starter-project template tests
Last synced: about 1 month ago
JSON representation
Starter Project for Approval Tests implementation in Dart
- Host: GitHub
- URL: https://github.com/approvals/approvaltests.dart.starterproject
- Owner: approvals
- Created: 2024-05-10T17:24:24.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-29T17:24:09.000Z (6 months ago)
- Last Synced: 2024-06-29T18:35:28.213Z (6 months ago)
- Topics: approval-tests, approvals, approvals-dart, dart, starter-project, template, tests
- Language: Dart
- Homepage: https://github.com/approvals/ApprovalTests.Dart
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
Starter Project for Approval Tests implementation in Dart 🚀
## 📖 About
**[Approval Tests](https://approvaltests.com/)** are an alternative to assertions. You’ll find them useful for testing objects with complex values *(such as long strings)*, lots of properties, or collections of objects.
`Approval tests` simplify this by taking a snapshot of the results, and confirming that they have not changed.
In normal unit testing, you say `expect(person.getAge(), 5)`. Approvals allow you to do this when the thing that you want to assert is no longer a primitive but a complex object. For example, you can say, `Approvals.verify(person)`.
I am writing an implementation of **[Approval Tests](https://approvaltests.com/)** in Dart. If anyone wants to help, please **[text](https://t.me/yelmuratoff)** me. 🙏
## 📦 Installation
Add the following to your `pubspec.yaml` file:
```yaml
dependencies:
approval_tests: ^0.4.5
```## 📚 How to use
### Approving Results
Approving results just means saving the `.approved.txt` file with your desired results.
We’ll provide more explanation in due course, but, briefly, here are the most common approaches to do this.
#### • Via Diff Tool
Most diff tools have the ability to move text from left to right, and save the result.
How to use diff tools is just below, there is a `Comparator` class for that.#### • Via approveResult property
If you want the result to be automatically saved after running the test, you need to use the `approveResult` property in `Options`:```dart
test('test complex JSON object', () {
var complexObject = {
'name': 'JsonTest',
'features': ['Testing', 'JSON'],
'version': 0.1,
};
ApprovalTests.verifyAsJson(
complexObject,
options: const Options(
approveResult: true,
),
);
});
```#### • Via file rename
You can just rename the `.received` file to `.approved`.### Comparators
You can use different comparators to compare files. The default is `CommandLineComparator` which compares files in the console.
To use `IDEComparator` you just need to add it to `options`:
```dart
options: const Options(
comparator: IDEComparator(
ide: ComparatorIDE.visualStudioCode,
),
),
```But before you add an `IDEComparator` you need to do the initial customization:
- **Visual Studio Code**
- For this method to work, you need to have Visual Studio Code installed on your machine.
- And you need to have the `code` command available in your terminal.
- To enable the `code` command, press `Cmd + Shift + P` and type `Shell Command: Install 'code' command in PATH`.- **IntelliJ IDEA**
- For this method to work, you need to have IntelliJ IDEA installed on your machine.
- And you need to have the `idea` command available in your terminal.
- To enable the `idea` command, you need to create the command-line launcher using `Tools - Create Command-line Launcher` in IntelliJ IDEA.- **Android Studio**
- For this method to work, you need to have Android Studio installed on your machine.
- And you need to have the `studio` command available in your terminal.
- To enable the `studio` command, you need to create the command-line launcher using `Tools - Create Command-line Launcher` in Android Studio.
## 📝 Examples
I have provided a couple of small examples here to show you how to use the package.
There are more examples in the `example` folder for you to explore. I will add more examples in the future.
Inside, in the `gilded_rose` folder, there is an example of using `ApprovalTests` to test the legacy code of [Gilded Rose kata](https://github.com/emilybache/GildedRose-Refactoring-Kata).
You can study it to understand how to use the package to test complex code.And the `verify_methods` folder has small examples of using different `ApprovalTests` methods for different cases.
## ❓ Which File Artifacts to Exclude from Source Control
You must add any `approved` files to your source control system. But `received` files can change with any run and should be ignored. For Git, add this to your `.gitignore`:```gitignore
*.received.*
```## ✉️ For More Information
### Questions?
Ask me on Telegram: [`@yelmuratoff`](https://t.me/yelmuratoff).
Email: [`[email protected]`](mailto:[email protected])### Video Tutorials
- [Getting Started with ApprovalTests.Swift](https://qualitycoding.org/approvaltests-swift-getting-started/)
- [How to Verify Objects (and Simplify TDD)](https://qualitycoding.org/approvaltests-swift-verify-objects/)
- [Verify Arrays and See Simple, Clear Diffs](https://qualitycoding.org/verify-arrays-approvaltests-swift/)
- [Write Parameterized Tests by Transforming Sequences](https://qualitycoding.org/parameterized-tests-approvaltests-swift/)
- [Wrangle Legacy Code with Combination Approvals](https://qualitycoding.org/wrangle-legacy-code-combination-approvals/)You can also watch a series of short videos about [using ApprovalTests in .Net](https://www.youtube.com/playlist?list=PL0C32F89E8BBB5368) on YouTube.
### Podcasts
Prefer learning by listening? Then you might enjoy the following podcasts:- [Hanselminutes](https://www.hanselminutes.com/360/approval-tests-with-llewellyn-falco)
- [Herding Code](https://www.developerfusion.com/media/122649/herding-code-117-llewellyn-falcon-on-approval-tests/)
- [The Watir Podcast](https://watirpodcast.com/podcast-53/)## 🤝 Contributing
Show some 💙 and star the repo to support the project! 🙌
The project is in the process of development and we invite you to contribute through pull requests and issue submissions. 👍
We appreciate your support. 🫰