#๐Ÿ”’ Need some help with understanding writing unit tests

9 messages ยท Page 1 of 1 (latest)

sage agate
#

I'm trying to understand how people know how and what to test for their project? I am relatively new to programming and have used AI to write my unit tests before. I've found writing tests by hand to be very tedious and error prone. I am wondering if this is an acceptable use case for AI and if anyone else has experience with this. Thank you ! ๐Ÿ™‚ ๐Ÿฑ

Are tests usually just:

def func_to_test(val): ...

class Test(unittest.TestCase):
  def test_func(self):
      self.assertEqual(func_to_test(val), CorrectValue)
shadow bluffBOT
#

@sage agate

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

midnight lagoon
#

You want to test for edge cases as well. Correct input is obvious, but incorrect in it is often overlooked. What happens when a number is passed instead of a string? What happens when the string is not in the correct format? It's good to have positive that assert that the code works in the ideal circumstances, but you also want to write tests for what happens the input is not perfect.

sage agate
#

I see, do you have any experience with how accurate ai is for writing unit test? I ask because I've wrote tests one time and it was very boring... ๐Ÿ˜…

midnight lagoon
#

I do. I am actually currently using AI to write a lot of tests.

The thing is though, I also have a lot of prior experience writing tests. A major problem with using AI to write tests, is it can often write useless tests. You need to be able to identify the value of a test an AI (or junior developer) had written, and you get that from writing your own tests. AI is not an out here.

#

Unit tests are boring, and are generally not considered to be a appealing stage of development. You still need to be able to write and understand them regardless, though.

sage agate
#

Do you have any resources for writing good tests? How can I verify I'm not writing bad tests? I'm going to try to write more tests by hand until I can get a good grasp on it. ๐Ÿ‘

shadow bluffBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.