hide testcode just for one test case but display testcode for "use as example" test case

hide testcode just for one test case but display testcode for "use as example" test case

by fab med -
Number of replies: 3

Hello,

I would like to display a full test case in java (testcode + output expected + output got) as example but I have another test case and I don't want to display the testcode for this one. Only "expected" and "got" output.

I tried with [["Expected", "expected"], ["Got", "got"]] but it hides testcode for all test cases.

Could you help me ?

Thank you

Fab

In reply to fab med

Re: hide testcode just for one test case but display testcode for "use as example" test case

by Richard Lobb -
The way I handle this case is to use the test.extra field for the actual test code, putting just a comment in the testcode field like

// Running hidden tests.
You will have to modify the question template to include the test.extra code immediately after test.testcode. For example, if it's a Java Method question, the test loop would become something like
{% for testCase in TESTCASES %}
    {
    {{ testCase.testcode }};
    {{ testCase.extra }};
    {% if not loop.last %}
    System.out.println(SEPARATOR);
    {% endif %}
    }
    {% endfor %}
    

Warning - I haven't tested this in Java but it (or something very like it) should work.

In reply to Richard Lobb

Re: hide testcode just for one test case but display testcode for "use as example" test case

by fab med -
Hi Richard,
Thank you for your help.
In my case I'm working with Java Class question, so it seems that your hint doesn't work for me. I tried but the tests no longer pass.
Would it be possible to check the test number and if it is a certain value to ensure that only the "got" column is output?
Thank you
In reply to Richard Lobb

Re: hide testcode just for one test case but display testcode for "use as example" test case

by fab med -
Done !

{{ STUDENT_ANSWER | replace({'public class ': 'class '}) }}

public class __tester__ {

public static void main(String[] args) {
__tester__ main = new __tester__();
main.runTests();
}

public void runTests() {
{{ TEST.extra}}
{{ TEST.testcode }}
}
}

Thank you very much !!