Library › Coding AI › College students

Write 4 unittest boundary tests when pytest isn't allowed

Practice: Setting limits and rules. About 5 minutes.

About this exercise

Your club's gradebook script runs on a lab machine where only the standard library is installed, so tests must use unittest, not pytest. Write one TestCase class named TestLetter with exactly 4 test methods: letter(90) == 'A', letter(89) == 'B', letter(0) == 'F', and letter(101) raises ValueError (with assertRaises). Import only unittest and letter from grades, and end with the unittest.main() guard. Exactly 1 code block of at most 18 lines, under 20 words of text.

Common mistakes when you ask AI for this

  • Getting pytest. pytest is the AI's default, and the lab box can't install it. Try: Add: "Standard library only: unittest.TestCase, no pytest."
  • Too many tests. The AI tests every tier and the future D tier too. Try: Say: "Exactly 4 test methods: 90 -> A, 89 -> B, 0 -> F, 101 raises ValueError."
  • Missing the runner guard. Without unittest.main(), running the file directly does nothing. Try: Add: "Import only unittest and letter; end with the unittest.main() guard."
  • An explanation of testing. The AI explains how unittest works. Try: Add: "Only the code block."

What a strong prompt includes

  • Names the framework
  • Sets the number of tests
  • Lists the boundary cases
  • Limits imports
  • Asks for the main guard

Practice this now ↑

Related exercises