DocuMesh / conception

General conceptual work.
Apache License 2.0
0 stars 0 forks source link

Mocking with BDD #3

Open BeWut opened 5 years ago

BeWut commented 5 years ago

Introduction

BDD Frameworks like cucumber are usually designed to work well with frontends but not with mocked backend tests. For this it's necessary to share the State of the test between the test steps. Unfortunately this is not possible out of the box and you'd need to resort to global variables in step libraries, polluting the actual test code.

Solution

A small scale object to step storage that can be reset for each complete test but keeps the data between single steps of the same test. For ease of use it should feature a fluent api like the following example:

klingerr commented 5 years ago

There should be a possibility to mock or spy saved results.

BeWut commented 5 years ago

My first idea would be to enhance every stored object with a customizable hook in the form of:

public interface EntityEnhancer<T> {
    T enhance(T entity);
}

Unfortunately that wouldn't allow us to change the object at will as we would need to keep the same object type. Probably an encoding/decoding approach might work.