Created
February 28, 2022 19:07
-
-
Save geryxyz/6e9b23ce4fbb22f1b86f066004c2a612 to your computer and use it in GitHub Desktop.
Decouple test cases from system under test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
class ClassA(object): | |
def apply(self, *args): | |
return 42 | |
class ClassB(object): | |
def apply(self, *args): | |
return 0 | |
def func_gamma(something): | |
... | |
def func_delta(): | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.parametrize(argnames='correct_class', argvalues=[ClassA, ClassB]) | |
def test_decoupled_from_class(correct_class): | |
# arrange | |
params = "hello" | |
# act | |
object_under_test = correct_class() | |
actual = object_under_test.apply(params) | |
# assert | |
expected = 42 | |
assert actual == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.parametrize(argnames='function_under_test', argvalues=[func_delta, func_gamma]) | |
def test_decoupled_from_function(function_under_test): | |
# arrange | |
params = "hello" | |
# act | |
actual = function_under_test(params) | |
# assert | |
expected = 42 | |
assert actual == expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment