BDD example implementation
mkschulze opened this issue · 3 comments
It would be a great help for me to have a few reference examples to work with.
The feature file I reference is here: https://github.com/Humans-of-Julia/GraknClient.jl/blob/BDD--steps/test/behaviour/features/concept/thing/attribute.feature
Connection example
- Gherkin
Feature: Concept Attribute
Background:
Given connection does not have any database
- Python
@step("connection does not have any database")
def step_impl(context: Context):
assert len(context.client.databases().all()) == 0
- Java
@Given("connection does not have any database")
public void connection_does_not_have_any_database() {
super.connection_does_not_have_any_database();
}
- Julia # this should be correct perhaps
@given("connection does not have any database") do context
@expect length(get_all(databases(context[:client]))) == 0
end
Put attribute example
- Gherkin
Background:
# Write schema for the test scenarios
Given put attribute type: is-alive, with value type: boolean
- Java
@When("{var} = attribute\\( ?{type_label} ?) as\\( ?boolean ?) put: {bool}")
public void attribute_type_as_boolean_put(String var, String typeLabel, boolean value) {
put(var, tx().concepts().getAttributeType(typeLabel).asBoolean().asRemote(tx()).put(value));
}
- Julia
@when("{var:Var} = attribute({type_label}) as(boolean) put: {value:Bool}") do context
context[Symbol(var)] = [:tx(), :concepts(), get_attribute_type(:type_label::String), :as_remote(context[:tx()]), :as_boolean(), :put(value::bool)]
end
especially this is pretty surely wrong:
[:tx(), :concepts(), get_attribute_type(:type_label::String), :as_remote(context[:tx()]), :as_boolean(), :put(value::bool)]
entity Set owns attribute example
- Gherkin
Feature: Concept Attribute
Background:
Given put entity type: person
Given entity(person) set owns attribute type: is-alive
- Java
@When("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label}")
public void thing_type_set_has_attribute_type(RootLabel rootLabel, String typeLabel, String attributeLabel) {
AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel);
get_thing_type(rootLabel, typeLabel).asRemote(tx()).setOwns(attributeType);
}
- Julia suggestion from suggestmissingsteps
@given("entity(person) set owns attribute type: is-alive") do context
@fail "Implement me"
end
- Julia
@given("{root_label}({type_label}) set owns attribute type: {type_label}") do context
@expect "Implement me"
end
These examples are pretty good.
Reviewing the source code, there are several static variables that are being mutated by steps.
For example, the sessions
variable is being set by some steps:
So if we want to run them, we will probably need to do something similar. I'm unsure if it has to be global though (static in Java would be the same thing as global in Julia) unless the variables are needed across BDD test cases. On the safe side we can do that for now.
Finally, you can't possibly run these tests yet until the "concepts" work is done. I just reviewed those code today and I have some ideas. I may not get to them today but I hope to have something more concrete by next week.
yes, it's just the Julia syntax I'm not sure about how to approach in the cases I mentioned, that's why it would be great to see them translated, so I can orientate here.
But yes, as we need to call those functions of the concepts, we shall implement them first and then see how to do it ideally.
I think we can close this issue. We have now a part of fully implemented BDD tests within the connection section of BDD tests of the client.