Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tesonep/parametrizedtests
https://github.com/tesonep/parametrizedtests
pharo testing
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tesonep/parametrizedtests
- Owner: tesonep
- License: mit
- Created: 2018-07-30T12:48:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-23T16:26:20.000Z (almost 5 years ago)
- Last Synced: 2024-11-17T07:34:39.758Z (about 1 month ago)
- Topics: pharo, testing
- Language: Smalltalk
- Size: 15.6 KB
- Stars: 4
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an small implementation of parametrized tests for Pharo.
It allows to generate different test cases for each of the possible configurations in a matrix.# Installing
To use it, it should be installed in Pharo. To install it with Metacello execute
```Smalltalk
Metacello new
baseline: 'ParametrizedTests';
repository: 'github://tesonep/parametrizedTests';
load.
```# Using
Once installed, there is a new subclass of *TestCase* called *ParametrizedTestCase*.
This is the class all the test cases using parametrized tests should use.
It extends the default *TestCase* with support for parametrized tests.A parametrized tests is a test that is run with different configurations.
These configurations are generated from a Matrix.To Parametrized tests just extend this class as a normal tests,
add accessors for the properties to configure and implement the class side method #testParameters.When the test class is executed a TestSuite is generated with an instance for each of the configured cases. This instances are populated using the accessors to the described properties.
The class side method #testParameters returns a test matrix.
This test matrix can be generated with cartesian product configurations or a set of well known cases.An example of #testParameters is:
```Smalltalk
MyTestCase class >> testParameters^ ParametrizedTestMatrix new
forSelector: #option1 addOptions: #(a b c);
forSelector: #option2 addOptions: {[1].[2].[3]};
yourself.
```Each option is constituted from a set of possible values and a selector that is the name of the property to set in the test case instance.
Also each option can be a literal or a block to generate that value. The block has an optional parameter, the parameter is the test case to configure.
In this example the generated cases will be 9. One per each combination of #option1 and #option2.
The test Case should have a setter forCheck the Examples to see how to use the different possible configurations.
# Examples
The API is quite simple, but there are two simple examples to show the use of generated matrix and set of cases.
The example class *PaSimpleMatrixExampleTest* shows an example of a matrix.```Smalltalk
PaSimpleMatrixExampleTest class >> testParameters^ ParametrizedTestMatrix new
forSelector: #item1 addOptions: { 1. 'a'. $c };
forSelector: #item2 addOptions: { 2. 'b'. $d };
forSelector: #collectionClass addOptions: { Set. Bag. OrderedCollection }
```This example generates 81 different cases, with all the combinations.
The second example uses a set of given cases. This example is shown in the test class *PaSelectedCasesExampleTest*
```Smalltalk
PaSelectedCasesExampleTest class >> testParameters^ ParametrizedTestMatrix new
addCase: { #number1 -> 2. #number2 -> 1.0. #result -> 3 };
addCase: { #number1 -> (2/3). #number2 -> (1/3). #result -> 1 };
yourself
```This example generates exactly the two cases listed in the test.