def make_test_output(test_name=None, score=0, max_score=0, output="", visibility=None):
    """
    Return a dictionary representing results of a test.
    Fields are valid Gradescope autograder JSON.
    """
    result = {
        "score": score,
        "max_score": max_score,
        "output": output
    }
    if visibility:
        if visibility == "hide_message":
            result["visibility"] = "visible"
            result["output"] = ""
        else:
            result["visibility"] = visibility
    if test_name:
        result["name"] = test_name

    return result