Skip to content

Commit 9657cef

Browse files
authored
Merge pull request #3 from DutchCodingCompany/feature/add_flutter
Improving multiple version of the package
2 parents c2908e8 + 3237ca1 commit 9657cef

24 files changed

+817
-64
lines changed

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+
## 0.2.0
2+
3+
- Fixed some issues with seperate parameterized_test variances
4+
15
## 0.1.0
26

37
- Created flutter variance of parameterized_test

packages/flutter_parameterized_test/LICENSE

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Dutch Coding Company B.V.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/flutter_parameterized_test/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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.
4+
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 :)

packages/flutter_parameterized_test/example/flutter_parameterized_test_example.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter_parameterized_test/flutter_parameterized_test.dart';
22
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:parameterized_source/parameterized_source.dart';
34

45
void main() {
56
parameterizedTest(
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
library flutter_parameterized_test;
22

33
export 'flutter_parameterized_test_base.dart';
4-
export 'package:parameterized_test/src/parameterized_source.dart';

packages/flutter_parameterized_test/lib/flutter_parameterized_test_base.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'package:meta/meta.dart';
2-
import 'package:parameterized_test/src/parameterized_source.dart';
31
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:meta/meta.dart';
3+
import 'package:parameterized_source/parameterized_source.dart';
44

55
/// Create a group of parameterized tests.
66
///
@@ -30,21 +30,22 @@ import 'package:flutter_test/flutter_test.dart';
3030
/// );
3131
/// ```
3232
@isTestGroup
33-
void parameterizedTest(Object description,
34-
ParameterizedSource parameters,
35-
void Function(List<dynamic> values) body, {
36-
String? testOn,
37-
Timeout? timeout,
38-
dynamic skip,
39-
dynamic tags,
40-
Map<String, dynamic>? onPlatform,
41-
int? retry,
42-
}) {
33+
void parameterizedTest(
34+
Object description,
35+
ParameterizedSource parameters,
36+
void Function(List<dynamic> values) body, {
37+
String? testOn,
38+
Timeout? timeout,
39+
dynamic skip,
40+
dynamic tags,
41+
Map<String, dynamic>? onPlatform,
42+
int? retry,
43+
}) {
4344
group(description, () {
4445
for (final parameter in parameters.params) {
4546
test(
4647
parameter,
47-
() => body(parameter),
48+
() => body(parameter),
4849
testOn: testOn,
4950
timeout: timeout,
5051
skip: skip,
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: flutter_parameterized_test
22
description: Simple package that helps with executing parameterized tests. Inspired by JUnit ParameterizedTest CsvValues.
3-
version: 0.1.0
3+
version: 0.2.0
44
homepage: https://www.github.com/DutchCodingCompany/parameterized_test
55

66
environment:
77
sdk: '>=2.12.0 <3.0.0'
88

99
dependencies:
10-
meta: ^1.7.0
10+
meta: ^1.8.0
1111
flutter:
1212
sdk: flutter
13-
parameterized_test: 0.1.0
14-
15-
dev_dependencies:
1613
flutter_test:
1714
sdk: flutter
18-
lints: ^1.0.1
15+
parameterized_source: ^0.2.0
16+
17+
dev_dependencies:
18+
lints: ^2.0.0

packages/flutter_parameterized_test/test/flutter_parameterized_source_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'package:flutter_parameterized_test/flutter_parameterized_test.dart';
21
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:parameterized_source/parameterized_source.dart';
33

44
void main() {
55
group('ParameterizedSource.csv tests', () {

0 commit comments

Comments
 (0)