Open BeWut opened 5 years ago
There should be a possibility to mock or spy saved results.
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.
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:
ScenarioResult.initialize();
ScenarioResult.addResult(object).toGivenStep();
ScenarioResult.addResultListofType(Object.class).with(objectList).toGivenStep();
ScenarioResult.getResultofType(Object.class).fromGivenStep().asSingleResult();
ScenarioResult.getResultofType(Object.class).fromGivenStep().asResultList();
ScenarioResult.getResultofType(Object.class).fromGivenStep().asSingleResult(new EntityIdentifier<Object>() {...});