-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateTests.java
71 lines (60 loc) · 2.09 KB
/
TemplateTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package src;
import org.junit.Test;
import static org.junit.Assert.*;
import java.text.MessageFormat;
import student.Translations.Translator;
import StudentCode.*;
import student.*;
{{ ADDITIONAL_IMPORTS }}
public class Tests {
@Test
public void tests(){
{{ PREVIOUS_CODE }}
{{ STUDENT_INSTANCE }}
{%- for test in tests %}
{% if "hidden" not in test or not test["hidden"] %}
{%- if "previousCalls" in test -%}{{ instancesToCall[loop.index0] }}.{{ test.previousCalls }};{% endif %}
{%- if askFor == "class" %}
try {
{{ namesAsk[loop.index0] }}.class.getDeclaredMethod({{ testsName[loop.index0] }});
} catch (NoSuchMethodException e){
fail("You should have a method {{ testsName[loop.index0].split('\"')[1].split('\"')[0] }}");
}
{%- endif %}
{% if test["test"].startswith("test") -%}
try {
{{ instancesToCall[loop.index0] }}.{{ test.test }};
} catch (AssertionError e){
fail("vos tests pour testIsADN ne passent pas");
}
{% elif "exceptionExpected" in test and test["exceptionExpected"] -%}
try {
{{ instancesToCall[loop.index0] }}.{{ test.test }};
fail("You did not catch {{ test.exceptionExpected }}");
} catch ({{ test.exceptionExpected }} e){
} catch (Exception e){
fail("Unexpected exception");
}
{% else -%}
try{
{%- if "checkConsole" in test and test["checkConsole"] %}
ByteArrayOutputStream baos{{loop.index0}} = new ByteArrayOutputStream();
PrintStream ps{{loop.index0}} = new PrintStream(baos{{loop.index0}});
System.setOut(ps{{loop.index0}});
{{ instancesToCall[loop.index0] }}.{{ test.test }};
System.out.flush();
System.setOut(old);
student_answer = baos{{loop.index0}}.toString();
{% endif %}
assertTrue(
{{ errorsFeedbacks[loop.index0] }},
{{ assertionsResults[loop.index0] }}
);
} catch(Exception e){
fail("Unexpected exception");
}
{% endif -%}
{% endif -%}
{%- endfor %}
}
}