I'm integration testing a system, by using only the public APIs. I have a test that looks something like this:
def testAllTheThings(): email = create_random_email() password = create_random_password() ok = account_signup(email, password) assert ok url = wait_for_confirmation_email() assert url ok = account_verify(url) assert ok token = get_auth_token(email, password) a = do_A(token) assert a b = do_B(token, a) assert b c = do_C(token, b) # ...and so on...
Basically, I'm attempting to test the entire "flow" of a single transaction. Each step in the flow depends on the previous step succeeding. Because I'm restricting myself to the external API, I can't just go poking values into the database.
So, either I have one really long test method that does `A; assert; B; assert; C; assert...", or I break it up into separate test methods, where each test method needs the results of the previous test before it can do its thing:
def testAccountSignup(): # etc. return email, password def testAuthToken(): email, password = testAccountSignup() token = get_auth_token(email, password) assert token return token def testA(): token = testAuthToken() a = do_A(token) # etc.
I think this smells. Is there a better way to write these tests?