AcademySoftwareFoundation / OpenTimelineIO

Open Source API and interchange format for editorial timeline information.
http://opentimeline.io
Apache License 2.0
1.45k stars 286 forks source link

BDD Testing #1228

Open KarthikRIyer opened 2 years ago

KarthikRIyer commented 2 years ago

Feature Request

Proposal to add BDD (Behaviour Driven Development) tests to the project.

Description

I'm thinking of migrating to BDD tests in the Java bindings using spock, a groovy framework. I thought it might be helpful to do the same for the python tests.

The idea of BDD testing is to write tests in a simple user/business friendly manner. The tests become a documentation in themselves. For example:

If we want to write a simple test to see if disabling an Item works...

The BDD specification would be like:

given: "An item is created"
when: "Item is disabled"
then: "Item does not contribute to the composition"

And the code in groovy would be like:

given: "An item is created"
def item = new Item()
verify {
    item.enabled() == true
}

when: "Item is disabled"
item.setEnabled(false)

then: "Item does not contribute to the composition"
verifyAll {
        item.isEnabled() == false
}

It might be a lot of effort in the beginning but once you get used to it, it becomes simpler and clearer. It'll also be helpful to community members new to the project. The current tests might not be very clear to them.

There are a couple of BDD testing frameworks in python (framework comparison). The most popular and powerful seems to be behave. There's also pytest-bdd which is compatible with pytest. Does anybody have an opinion or idea on what could be used? I tried using behave and implemented a tutorial. Seems simple enough.

Any thought on taking this forward? Or should we continue writing unit test as we do right now?

Context

Here's the Java bindings PR where I discussed with Eric about this: #57

reinecke commented 2 years ago

I’ve long been a fan of pytest and would support us switching over. It seems to have pretty wide adoption at this point and I think it would provide some tools that would simplify a lot of our test code.

While BDD testing in Spock is pretty elegant, the BDD solutions for python feel to me like they’d be heavy to maintain. Every test requires keeping two files in sync with one another and there is a lot of boilerplate (in separate functions with specific decorators) required to implement them.

My vote at the moment would be to migrate to pytest, but defer on BDD unless a more elegant solution shows up.

reinecke commented 2 years ago

The thumbsup from @apetrynet also reminded me, when he created the plugin template, we accepted pytest into the otio ecosystem in a subtle way. So there is some precedent and example of how we can integrate pytest.