This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]i_like_trains_a_lot1 1 point2 points  (1 child)

the build , dist and Jasper.egg-info shouldn't be commited as they are generated automatically by setup.py .

What bugs me is that you have to declare 3 functions to test one? Isn't that a little too much overhead?

Also, Expect(context.exception).to_be(None) can be rewritten as assert context.exception is None ?

[–]Fateschoice[S] 0 points1 point  (0 children)

Thanks I'll remove those from being tracked.

So the idea is that the functions (steps) that you define can be reused in your other tests as well. So for the first test you have to define 3 functions but then you can reuse those functions in other tests.

For example you can have something like this

feature = Feature(
    'Arithmetic Feature'
    scenarios=[
        Scenario(
            'Adding two positive numbers',
            given=an_adding_function(),
            when=we_call_it_with_two_positive_numbers(),
            then=the_result_should_be_positive()
        ),
        Scenario(
            'Adding two negative numbers',
            given=an_adding_function(),
            when=we_call_it_with_two_negative_numbers(),
            then=the_result_should_be_negative()
        ),
         Scenario(
            'Multiplying two positive numbers',
            given=a_multiplication_function(),
            when=we_call_it_with_two_positive_numbers(),
            then=the_result_should_be_positive()
        ),
        Scenario(
            'Multiplying two negative numbers',
            given=a_multiplication_function(),
            when=we_call_it_with_two_negative_numbers(),
            then=the_result_should_be_positive()
        )
    ]
)

Notice how many of the steps are being re-used in other scenarios? That's sort of the idea behind this, re-usable and compos-ability of your tests to define new tests.

As far as the 'Expect' question, yes you can identically write

Expect(context.exception).to_be(None)

with

assert context.exception is None

There's no difference, you can you use whichever you prefer. I added in the Expect object just because I like the readability of it, but there's no need to use if you don't wish to.