Assertions and Unit Testing

Python

Full documentation - https://docs.python.org/3/library/unittest.html

Why use assertListEqual() instead of just assertEqual()? Well, they are designed to show the difference between the two values on failure. So students will receive more accurate feedback if you use the proper assertion.

Feedback:

You can add feedback to assertion failures to alert students what they might have done wrong. To do so, just simply add an additional argument as a string containing the message you want to display.

assertEqual(student_output, real_output, "Looks like your code is not outputing the proper value.")

Useful Links:

Java

Full documentation - https://junit.org/junit4/javadoc/4.12/org/junit/Assert.html

Feedback:

You can add feedback to assertion failures to alert students what they might have done wrong. To do so, just simply add a string containing the message you want to display as the first argument in the method call.

assertEquals("Looks like your code is not outputing the proper value.", realOutput, studentOutput)

Ruby

Ruby calls assertions "matchers"

Full documentation - https://rspec.info/documentation/3.9/rspec-expectations/RSpec/Matchers.html

Last updated