Skip to content

Commit 5bd4aa6

Browse files
authored
Merge pull request #5 from DutchCodingCompany/rework/v1.0.0
Rework for v1.0.0-rc1
2 parents f824a51 + d40e820 commit 5bd4aa6

37 files changed

+2040
-500
lines changed

.github/workflows/dart.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Dart
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
branches: [ "main" ]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: ./packages/parameterized_test
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
# Note: This workflow uses the latest stable version of the Dart SDK.
25+
# You can specify other versions if desired, see documentation here:
26+
# https://github.com/dart-lang/setup-dart/blob/main/README.md
27+
# - uses: dart-lang/setup-dart@v1
28+
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603
29+
30+
- name: Install dependencies
31+
run: dart pub get
32+
33+
- name: Check code format
34+
run: dart format . -o none --set-exit-if-changed
35+
36+
# Uncomment this step to verify the use of 'dart format' on each commit.
37+
# - name: Verify formatting
38+
# run: dart format --output=none --set-exit-if-changed .
39+
40+
# Consider passing '--fatal-infos' for slightly stricter analysis.
41+
- name: Analyze project source
42+
run: dart analyze
43+
44+
# Your project will need to have tests in test/ and a dependency on
45+
# package:test for this step to succeed. Note that Flutter projects will
46+
# want to change this to 'flutter test'.
47+
- name: Run tests
48+
run: dart test

README.md

Lines changed: 147 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,79 +11,172 @@ and the Flutter guide for
1111
[developing packages and plugins](https://flutter.dev/developing-packages).
1212
-->
1313

14-
# Parameterized test
14+
# 🧪 Parameterized test
1515

16-
Simple package that helps with executing parameterized tests. Inspired by [JUnit ParameterizedTest CsvValues](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests-sources-CsvSource). This package is a wrapper around `groups` and `test`.
16+
Supercharge your Dart testing with **parameterized_test**! Built on top of the [dart test package](https://pub.dev/packages/test), this [JUnit ParameterizedTest](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests) inspired package wrap around `group` and `test` to take your testing to the next level!
1717

18-
## Features
18+
## Table of contents
19+
* [Features](#features-)
20+
* [Installation](#installation)
21+
* [Usage](#usage)
22+
* [Examples](#examples)
23+
* [How it works](#how-it-works)
24+
* [Additional information](#additional-information)
1925

20-
This package helps executing a test multiple times with different parameters.
21-
Currently parameters can be specified as:
22-
- ParameterizedSource.csv
23-
- ParameterizedSource.value
24-
- ParameterizedSource.values
26+
## Features ✨
2527

26-
When using `ParameterizedSource.csv` the library tries to parse the values to `int`, `double`, `bool` or `String?`. If the csv value contains a empty string it will be parsed to null.
27-
This parsing can be escaped by wrapping in the values in `'` or `"`.
28+
- ✅ Run a test multiple times based on provide parameter list.
29+
- ✅ Uses [dart test package](https://pub.dev/packages/test) under the hood.
30+
- ✅ Type cast test parameters used in the tests.
31+
- ✅ Include test options for parameter_test.
32+
- ✅ Include test options per parameters.
2833

29-
For example:
34+
- ❌ No CSV parsing is supported. Its only possible to use Lists with actual values.
3035

31-
|Input | Output|
32-
|------|-------|
33-
|`'banana, 4, apple'`|`'banana'`, `4`, `'apple'`|
34-
|`'banana, 4, '`|`'banana'`, `4`, `null`|
35-
|`'banana, "4", apple'`|`'banana'`, `'4'`, `'apple'`|
36-
|`'banana, 4, ""'`|`'banana'`, `4`, `''`|
36+
## Installation
3737

38-
## Getting started
38+
```yaml
39+
dev_dependencies:
40+
parameterized_test: [latest-version]
41+
```
42+
43+
## Usage
44+
45+
Instead of using `groups` or `test` you can now use `parameterizedTest` and supply it list of test parameters to use in the same test.
46+
To specify the test body use `TestParametersX` that matches the same amount of test parameters for 1 test. For example when the test has 2 parameters `actual` and `expected` use `TestParameters2` for supplying the test body.
47+
The package offers `TestParameters` classes up to 10 parameters. Instead of writing `TestParameters` completely it also possible to use `typedef`'s `p1`..`p10`.
48+
49+
## Examples
50+
51+
Example parameterizedTest with 1 parameter:
52+
53+
```dart
54+
parameterizedTest(
55+
'Number are less than 4 tests',
56+
[
57+
1,
58+
2,
59+
3,
60+
],
61+
p1((int number) {
62+
final result = number < 4;
63+
expect(result, true);
64+
}),
65+
);
66+
```
67+
68+
Example parameterizedTest with 2 parameters:
69+
70+
```dart
71+
parameterizedTest(
72+
'Amount of letters tests',
73+
[
74+
['kiwi', 4],
75+
['apple', 5],
76+
['banana', 6],
77+
],
78+
p2((String word, int length) {
79+
expect(word.length, length);
80+
}),
81+
);
82+
```
83+
84+
Example parameterizedTest with extra test options for a value:
3985

40-
Include `parameterized_test` or when using `flutter_test` include `flutter_parameterized_test` in
41-
your projects `pubspec.yaml`.
86+
```dart
87+
parameterizedTest(
88+
'Amount of letters',
89+
[
90+
['kiwi', 4],
91+
['apple', 5],
92+
['banana', 6].withTestOptions(skip: true),
93+
],
94+
p2((String word, int length) {
95+
expect(word.length, length);
96+
}),
97+
);
98+
```
4299

43-
## Usage
100+
Example parameterizedTest with test enum values:
44101

45-
Instead of using `groups` or `test` you can now use `parameterizedTest` and supply it with multiple test parameters.
102+
```dart
103+
enum AwesomeEnum { such, woow, much, skill}
104+
105+
parameterizedTest(
106+
'Doge enum tests',
107+
AwesomeEnum.values,
108+
p1((AwesomeEnum doge) {
109+
final result = doge.name.length == 4;
110+
expect(result, true);
111+
}),
112+
);
113+
```
114+
115+
## How it works
116+
117+
`parameterized_test` is basically a wrapper that executes a `group` test and loops over the provide `List` of test values. Each set of values is cast to the specified type inside the body. Which is wrapped inside a `test`.
46118

47-
Csv source example:
48119
```dart
49120
parameterizedTest(
50121
'Amount of letters',
51-
ParameterizedSource.csv([
52-
'kiwi, 4',
53-
'apple, 5',
54-
'banana, 6',
55-
]),
56-
(List<dynamic> values) {
57-
final String input = values[0];
58-
final expected = values[1];
59-
60-
final actual = input.length;
61-
62-
expect(actual, expected);
63-
},
122+
[
123+
['kiwi', 4],
124+
['apple', 5],
125+
['banana', 6],
126+
],
127+
p2((String word, int length) {
128+
expect(word.length, length);
129+
}),
64130
);
65131
```
66132

67-
Values source example:
133+
The above example roughly translates to:
134+
```dart
135+
group('Amount of letter', () {
136+
final testValues = [
137+
['kiwi', 4],
138+
['apple', 5],
139+
['banana', 6],
140+
],
141+
142+
for(final testValue in testValues){
143+
test(testValue.toString(), () {
144+
final String word = testValue[0] as String;
145+
final int length = testValue[1] as int;
146+
147+
expect(word.length, length);
148+
});
149+
}
150+
});
151+
```
152+
153+
## Extending parameters
154+
155+
Currently the package supports `TestParameters` classes up to 10 arguments. If need to more arguments within a test than this is possible by implementing the `TestParameters` class.
156+
157+
For example:
68158
```dart
69-
parameterizedTest(
70-
'Amount of letters',
71-
ParameterizedSource.values([
72-
['kiwi', 4],
73-
['apple', 5],
74-
['banana', 6],
75-
]),
76-
(List<dynamic> values) {
77-
final String input = values[0];
78-
final expected = values[1];
79-
80-
final actual = input.length;
81-
82-
expect(actual, expected);
83-
},
84-
);
159+
class MyParameters implements TestParameters{
160+
const MyParameters(this.body);
161+
162+
@override
163+
final dynamic Function(A1, A2) body;
164+
165+
@override
166+
final int count = 2;
167+
168+
@override
169+
void mapBody<R>(Iterable<R> values) {
170+
final A1 a1 = values.elementAt(0) as A1;
171+
final A2 a2 = values.elementAt(1) as A2;
172+
body(a1, a2);
173+
}
174+
}
175+
176+
}
85177
```
86178

87179
## Additional information
88180

89-
Its just a simple wrapper to easily execute tests multiple times with different values. Feel free to leave some feedback or open an pull request :)
181+
Its just a simple wrapper to easily execute tests multiple times with different values. Feel free to
182+
leave some feedback or open an pull request :)

packages/flutter_parameterized_test/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-rc1
2+
3+
- DISCONTINUED `flutter_parameterized_test` package
4+
15
## 0.2.1
26

37
- Fixed issues with wrong dependencies
Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,4 @@
1-
<!--
2-
This README describes the package. If you publish this package to pub.dev,
3-
this README's contents appear on the landing page for your package.
1+
# Flutter_parameterized_test
42

5-
For information about how to write a good package README, see the guide for
6-
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
7-
8-
For general information about developing packages, see the Dart guide for
9-
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
10-
and the Flutter guide for
11-
[developing packages and plugins](https://flutter.dev/developing-packages).
12-
-->
13-
14-
# Parameterized test
15-
16-
Simple package that helps with executing parameterized tests. Inspired by [JUnit ParameterizedTest CsvValues](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests-sources-CsvSource). This package is a wrapper around `groups` and `test`.
17-
18-
## Features
19-
20-
This package helps executing a test multiple times with different parameters.
21-
Currently parameters can be specified as:
22-
- ParameterizedSource.csv
23-
- ParameterizedSource.value
24-
- ParameterizedSource.values
25-
26-
When using `ParameterizedSource.csv` the library tries to parse the values to `int`, `double`, `bool` or `String?`. If the csv value contains a empty string it will be parsed to null.
27-
This parsing can be escaped by wrapping in the values in `'` or `"`.
28-
29-
For example:
30-
31-
|Input | Output|
32-
|------|-------|
33-
|`'banana, 4, apple'`|`'banana'`, `4`, `'apple'`|
34-
|`'banana, 4, '`|`'banana'`, `4`, `null`|
35-
|`'banana, "4", apple'`|`'banana'`, `'4'`, `'apple'`|
36-
|`'banana, 4, ""'`|`'banana'`, `4`, `''`|
37-
38-
## Getting started
39-
40-
Include `parameterized_test` or when using `flutter_test` include `flutter_parameterized_test` in
41-
your projects `pubspec.yaml`.
42-
43-
## Usage
44-
45-
Instead of using `groups` or `test` you can now use `parameterizedTest` and supply it with multiple test parameters.
46-
47-
Csv source example:
48-
```dart
49-
parameterizedTest(
50-
'Amount of letters',
51-
ParameterizedSource.csv([
52-
'kiwi, 4',
53-
'apple, 5',
54-
'banana, 6',
55-
]),
56-
(List<dynamic> values) {
57-
final String input = values[0];
58-
final expected = values[1];
59-
60-
final actual = input.length;
61-
62-
expect(actual, expected);
63-
},
64-
);
65-
```
66-
67-
Values source example:
68-
```dart
69-
parameterizedTest(
70-
'Amount of letters',
71-
ParameterizedSource.values([
72-
['kiwi', 4],
73-
['apple', 5],
74-
['banana', 6],
75-
]),
76-
(List<dynamic> values) {
77-
final String input = values[0];
78-
final expected = values[1];
79-
80-
final actual = input.length;
81-
82-
expect(actual, expected);
83-
},
84-
);
85-
```
86-
87-
## Additional information
88-
89-
Its just a simple wrapper to easily execute tests multiple times with different values. Feel free to leave some feedback or open an pull request :)
3+
This package has been discontinued in favor
4+
of [parameterized_test](https://pub.dev/packages/parameterized_test) 1.0.0+.

0 commit comments

Comments
 (0)