I have a program that gives an output based on parameters object as input and information stored in a database.
I am trying to test this program with 2 test cases, the first of which gives no parameters. My program would then create a default parameters object and return it as part of the output, and then the second test would make a specific change to the parameters object and give it back to the program as input.
Currently I am doing this by combining the two test cases into one, to be able to save the parameters object in a local variable and change it and use it for the second one:
def test_function:
testData = {'name':"Test"}
response = self.app.post('/test', data=testData)
# make assert statements for first response
parameters = json.loads(response.data)['parameters']
parameters['foo'] = "bar"
testData['parameters'] = parameters
response = self.app.post('/test', data=testData)
# make assert statements for second response
Is there any way I could do this in two separate test cases? Or more importantly, SHOULD I do this in two separate test cases since the second one wouldn't be able to run if the first one doesn't work?
I cannot hard code the parameters object for the second test case because it is dependent on the data in the database, and part of the reason for testing is to see if the program works for different/no data.
Aucun commentaire:
Enregistrer un commentaire