HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

First time BDD: Testing the same things in both acceptance and unit tests

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
bddsamethethingsacceptanceteststimebothfirsttesting

Problem

I just tried BDD for the first time and implemented a simple Semantic Versioning Bumper in Python.

The class takes a version string in the format of major.minor.patch (i.e. 3.2.2, where major=3, minor=2, patch=2). Then you can bump a level, say patch, and you'd get 3.2.3. If you bump minor, you'd get 3.3.0 and if you bump major, you'd get 4.0.0.

For the BDD, I followed this workflow:

I wrote a high-level features file, then wrote the unit tests and then refactored until everything was working.

My problem is that both the unit tests and the acceptance tests are testing the same things, which doesn't feel right to me, but I don't know where to draw the line.

The code is not too complex so someone who is not too familiar with Python should be able to understand what's going on as well.

I would love to hear feedback regarding the implementation of my tests (or the actual code too, but mainly the tests).

This is the feature file:

Feature: Bump version strings

  Scenario: Increase patch version
    Given the version 0.1.2
      When we bump patch
      Then version is 0.1.3

  Scenario: Increase minor version
    Given the version 0.1.2
      When we bump minor
      Then version is 0.2.0

  Scenario: Increase major version
    Given the version 0.1.2
      When we bump major
      Then version is 1.0.0


This is the steps file:

@given('the version {version}')
def step_impl(context, version):
    context.versionbump = VersionBump(version)

@when('we bump {level}')
def step_impl(context, level):
    context.versionbump.bump(level)

@then('version is {version}')
def step_impl(context, version):
    context.versionbump.get() == version

@then('{level} is {number:d}')
def step_impl(context, level, number):
    assert context.versionbump.get(level) == number


These are the unit tests:

```
def test_same_version_after_parsing(vb):
assert vb.get_version() == '2.0.1'

def test_level_access(vb):
assert vb.get_level('major') == 2
assert vb.get_

Solution

Your problem seems to arise due to the fact, that your project is build from only one class (= unit).

With acceptance tests you test a non-programmers view of your project, that is whether it fullfills given requirements. Acceptance tests are formulated in a style of someone who actually uses features of your program and has no insights on what is going on behind the scenes.

With unit tests you test parts inside your program, which helps you (as a programmer) to verify, that single parts of your program work as expected. You could of course test functionality which the user of your program never gets to see directly.

Since your program has only one unit, your acceptance and unit tests are similar, but formulated differently. If your program was build from different units, the tests would indeed look more different.

Context

StackExchange Code Review Q#45118, answer score: 2

Revisions (0)

No revisions yet.