Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cucumber V5 #1449

Merged
merged 227 commits into from
Jul 31, 2019
Merged

Cucumber V5 #1449

merged 227 commits into from
Jul 31, 2019

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Sep 2, 2018

Summary

Development branch for v5. Mostly to keep my local artifacts properly versioned.

Closes: #1448

Notable changes so far

  • New internal package structure
  • New API package structure
  • Java and Java 8 modules have been merged
  • Now compiled as java 8.
  • Supports automatic module names
  • Supports repeatable annotations (Given, Given, Given).
  • Deprecate cucumber.api.cli.Main infavour of io.cucumber.core.api.cli.Main.|
  • Removed deprecated tags.
  • Fixed DEFAULT_BEFORE_ORDER not being set to the same value as DEFAULT_AFTER_ORDER
  • Backends are now loaded via ServiceLoaders. Indicated in io.cucumber.core.backend.BackendProvider
  • ObjectFactories are loaded via ServerLoader indicated in io.cucumber.core.backend.ObjectFactory
  • Any backend can now be created with an ObjectFactory
  • Java annotation and lambda based step defintions are now handled by different backends
  • Share single object factory between backends. Let Cucumber handle start/stop of object factory
  • Language from feature file will be used unless explicitly set using the TypeRegistryConfigurer.
  • Java supports annotation based parameter and data table types as well as default converters

After retiring Cucumber v4

  • Use Java 8s Instant and Clock in the event bus
  • Replace find and filter loops with streaming equivalents
  • Use lambdas for event handlers
  • Migrate to JUnit 5
  • Add docs for cucumber.properties to https://cucumber.io/docs/cucumber/configuration/
  • Add @FunctionalInterface to datatable and cucumber-expressions parameters

@mpkorstanje mpkorstanje added this to the 5.0.0 milestone Sep 2, 2018
mpkorstanje and others added 25 commits July 24, 2019 22:47
# Summary

By annotating methods parameter and data table types can be defined as 
part of the Glue. This enables them to access the test context and makes
them eligible for dependency injection. Additionally the type registry is
now created for each feature. This means the language of the feature will
be used to convert numbers.

## Details

## Parameter and DataTable Type

Introduces the `@ParameterType` and `@DataTableType` annotations. This
allows parameter and datatable types to be mapped to objects which can
only be created by services inside the test context.

For example in this scenario
```gherkin
Given the awesome catalog
When a user places the awestruck eels in his basket
Then you will be shocked at what happened next
```

We are now able to look up the "awestruck eels" in the "awesome" catalog.

```java
private final Catalog catalog;

@ParameterType(".*")
public Product product(String name) {
  return catalog.findProductByName(name);
}
```
## Default Transformer

It is now also possible to register default transformers using
annotations. Default transformers allow you to specific a transformer that
will be used when there is no transform defined. This can be combined with
an object mapper like Jackson to quickly transform well known string
representations to Java objects.

 * `@DefaultParameterTransformer`
 * `@DefaultDataTableEntryTransformer`
 * `@DefaultDataTableCellTransformer`

 ```java
package com.example.app;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.cucumber.java.DefaultDataTableCellTransformer;
import io.cucumber.java.DefaultDataTableEntryTransformer;
import io.cucumber.java.DefaultParameterTransformer;

import java.lang.reflect.Type;

public class DataTableSteps {

    private final ObjectMapper objectMapper = new ObjectMapper();

    @DefaultParameterTransformer
    @DefaultDataTableEntryTransformer
    @DefaultDataTableCellTransformer
    public Object defaultTransformer(Object fromValue, Type toValueType) {
        return objectMapper.convertValue(fromValue, objectMapper.constructType(toValueType));
    }
}
```

## Localization

Some languages uses comma's rather then points to separate decimals.
Previously to parse these properly you'd have to use
`TypeRegistryConfigurer.locale` to set this globally. When not explicitly
provided Cucumber will now take the language from the feature file. This
makes the following work without additional configuration:

```gherkin
# language: fr
Fonctionnalité: Concombres fractionnaires

  Scénario: dans la ventre
    Étant donné j'ai 5,5 concombres fractionnaires
```
```java
@Étantdonné("j'ai {bigdecimal} concombres fractionnaires")
public void jAiConcombresFractionnaires(BigDecimal arg0) {
    assertThat(arg0, is(new BigDecimal("5.5")));
}
```

# Motivation & Context

Fixes #851.
Fixes #1458.
Summary

In order to provide different test configurations it might be useful to use different object factories when working with
a DI framework. This is described in issue #1690.

Details

The annotations for JUnit and TestNG now allow to specify the class to instantiate as object factory. A CLI flag has
been added to allow the specification of an object factory on the command line (--object-factory). Some minor
refactorings along the way.

Motivation and Context

It is now possible to use different object factories in a Cucumber test suite. Features need to be separated (using
tags) and can be grouped as separate tests that are annotated with different CucumberOptions. For each specification of
CucumberOptions a different objectFactory can be specified. That way different feature tests can e.g. use differently
configured injectors. It is no longer necessary to specify an object factory in cucumber.properties. Object factories
are loaded via the ServiceLoader and need to be specified in the file
META-INF/services/io.cucumber.core.backend.ObjectFactory. Multiple implementations can be given here.
@mpkorstanje mpkorstanje merged commit 6289e7a into master Jul 31, 2019
@mpkorstanje mpkorstanje deleted the develop-v5 branch August 4, 2019 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use io.cucumber.<package-name> for the api