Hi everyone - I just wanted to introduce Kensa, my...
# feed
p
Hi everyone - I just wanted to introduce Kensa, my BDD testing framework for Kotlin and Java. It's just reached 1.0. You write Given-When-Then tests in plain Kotlin, running on JUnit, Kotest or TestNG. Kensa parses the test source at runtime and generates HTML reports that read as documentation, with real values in the sentences and sequence diagrams of the captured interactions. No Gherkin and no step definitions, so the docs can't drift from the tests. It's Apache 2.0 and is used by several dev teams at a large UK telco, on projects across Europe, over thousands of tests. Why and how: kensa.dev/blog/bdd-without-gherkin Docs: kensa.dev · GitHub: github.com/kensa-dev/kensa
o
Interesting approach for the audience you're describing. I understand that it's more about comprehensible reports and not necessarily about Gherkin, but I wonder how this might integrate with TestBalloon, which is capable of supporting any Gherkin style you want, generating custom reports in any format you'd like, plus parameterization in plain Kotlin, plus targets beyond the JVM.
p
Thanks. TestBalloon looks good, and those examples show nicely how far plain Kotlin can stretch a DSL. The difference is where the sentence comes from. In the behaviour-style example you linked,
Given("I eat 48 cucumbers") { eatCucumbers(48) }
states the step twice, once as a string and once as code, and nothing stops the two drifting apart. The parameterised version further down the same file gets values into the names with
Given("I enter $initial") { set(initial) }
, but the wording is still separate from the code. Kensa has no description strings. It parses the test source and renders the code itself, so
given(aCustomerWithAnOverdueInvoice())
reads as “given a customer with an overdue invoice”, with the runtime values filled in. Change the code and the report changes with it. On reports:
TestExecutionReport
gets a start and a finish event for each test element, plus the throwable if it failed. That’s a good hook for formatting results. But most of a Kensa report never reaches a test event: the values used inside the test, and the interactions between the system under test and its collaborators, which Kensa draws as sequence diagrams. On integration: Kensa runs on JUnit, Kotest and TestNG today, and it assumes a test is a function. That’s why only Kotest’s AnnotationSpec is supported. TestBalloon tests are named lambdas, so an adapter would mean teaching the parser to find
test("…") { }
blocks in the source. That’s doable on the JVM, and I’d be happy to talk about it if there’s interest. Beyond the JVM, though, no: Kensa reads test source and uses reflection at runtime, so it’s JVM-only. So far everyone using it has been on the JVM anyway. Parameterisation comes from the test framework underneath, e.g. JUnit’s
@ParameterizedTest
, and the parameter values appear in the report sentences.
o
Thanks for the explanations! I see your focus is on analyzing step functions which are called from a test function body, and creating reports from their function names. That pushes drift down by one level (there can still be drift between a step function’s name and its implementation). That’s of course a different application that something like TestBalloon’s custom reports cannot help with. Do I understand correctly that in your example you have the string description as a test function name (``order is rejected by fibre vision``), but you just don’t use it in reports? You say Kensa uses reflection, but the repo shows a compiler plugin. That looks like you might have more freedoms and could go beyond the JVM. But that’s just an observation, I’m not trying to suggest expanding your scope.
p
You’re right about the possibility of drift between a function name and implementation. Kensa still relies on developers being strict about naming, as good code does anyway. What it removes is the second copy: there’s no string to keep in step with a function, because the function name is the sentence. The values in the sentences are captured on the run, and the sequence diagrams come from the traffic the system actually sent, so those can’t drift. If a step says FibreVision rejects the order and the stub does something else, the diagram shows it. The name of the test function is used in the report. It’ll use back ticked ones as written, and un-camel others. Kensa uses both reflection and an optional compiler plugin for more complex capturing. Simple values are read by reflection, and the plugin injects hooks where a value has to be captured as a function runs. Source parsing and report generation still happen at runtime on the JVM. Parsing at compile time would open the door to other targets in principle, but nobody has asked for it yet.
thank you color 1