java_method testcases?

java_method testcases?

de Arpad Magosanyi -
Número de respuestas: 2

Two questions:

Q1:

I am trying to write a java_method question. I cannot figure out however how to write testcases.

What is expected to be in the Test Case field? An expression? A method? A class?

I tried all of the above with no success.

Q2:

Actually what I am trying to achieve would be another type of question; a koan. Like this:

"What you should be  written instead of __ to the following code to make the test pass?

@Test
public void assertEquals_tests_equality() {
  assertEquals(true,__);
}
"
And I would expect the answer to be simply "true".
Is it possible to achieve?


En respuesta a Arpad Magosanyi

Re: java_method testcases?

de Arpad Magosanyi -

Answer for Q1:

The second question authoring video helped to figure it out. If you check the "Customize" box, then the template will be shown, which helps to figure out what is expected.

The test should be a piece of code which you would put inside a method.
A System.out.println emitting some string, which should be the same as "Expected output" worked well for me.

I guess question2 can be handled by modifying the template.


En respuesta a Arpad Magosanyi

Re: java_method testcases?

de Arpad Magosanyi -

Answer for Q2:

Template:

public class __tester__ {
    static String SEPARATOR = "#<ab@17943918#@>#";
    Object __ = {{ STUDENT_ANSWER }};

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

    public void runTests() {
{% for testCase in TESTCASES %}
    {
    {{ testCase.testcode }};
    {% if not loop.last %}
    System.out.println(SEPARATOR);
    {% endif %}
    }
{% endfor %}
    }
}

Test case:
System.out.println(Boolean.TRUE.equals(__));