I’m looking for a prompt that would be able to consistently generate unit test based on a given code using Davinci codex. I get some mixed results when using my current prompt so I’m looking for prompt suggestions. I’m trying to achieve something like this
What’s your current prompt? Sometimes few shot with a few examples in the expected language helps.
2 Likes
Thanks Boris this is one I’ve tried
##### Create unit test for the source code below
### Python code
name = []
def set_name(self, user_name):
self.name.append(user_name)
return len(self.name) - 1
def get_name(self, user_id):
if user_id >= len(self.name):
return 'There is no such user'
else:
return self.name[user_id]
if __name__ == '__main__':
person = Person()
print('User Abbas has been added with id ', person.set_name('Abbas'))
print('User associated with id 0 is ', person.get_n
### Unit test for Python code
You may have more success trying to create a unit test for a single function. The code as presented above seems not to be correct, and is missing Person definition or import.
To force a unit test I might add def set_name_test(
after the comment to generate the unit test. This will prompt the model to create a function, which has test in its name, hopefully resulting in a testing of the set_name
function.
1 Like