Skip to content

Testing in a team

Learning objectives

  • understand .
For teachers

Prerequisites are:

  • Learners have .

Teaching goals are:

  • Learners .

Teaching form used:

  • .

Lesson plan:

  • 5 mins: prior knowledge
  • When one works in a team, how to make sure my code keeps doing the same?
  • Test everything? If no, what to test?

  • 5 mins: presentation

  • 10 mins: demonstration is_zero
  • 25 mins: challenge
  • 10 mins: feedback

Tests in a team

If all tests pass, we are -by definition- happy.

Programming team tresinformal

Problem

Q: When one works in a team, how to make sure my code keeps doing the same?

def get_test_dna_sequence():
  """Get a DNA sequence to be used in testing"""
  return "ACGTACGT"

. . .

A: Apply the Beyoncé Rule

Beyoncé rule

'If you like it, then you gotta put a test on it'

assert get_test_dna_sequence() == "ACGTACGT"

Teams should be reluctant to change tests: this will likely break other code.

Beyoncé

Source: Wikimedia

Untestable functions

Q: How to test this function?

def print_hello():
    print("Hello world")

. . .

A: Never write untestable functions

Making untestable functions testable

Q: How to make this function testable?

def print_hello():
    print("Hello world")

. . .

def get_hello_world_text():
    return "Hello world"

Testing graphical functions

Q: How to test this function thoroughly:

  • Plot looks pretty
  • Colors are correct
  • Trend line is drawn
def save_plot(filename, x_y_data):
    """Save the X-Y data as a scatter plot"""

. . .

A: usually: use a human, e.g. a code reviewer

In most cases, graphical analysis tools and/or AI are overkill. If you are stubborn: try!