-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathjunit
executable file
·94 lines (77 loc) · 1.61 KB
/
junit
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
export test_name="Test1"
j4(){
cat > src/"$test_name".java <<EOF
import static org.junit.Assert.*;
import org.junit.Test;
public class $test_name {
@Test
public void test(){
assertEquals("Error Message", 0, 0);
}
}
EOF
}
j5(){
cat > src/"$test_name".java <<EOF
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class $test_name {
@Test
public void test(){
assertEquals(0, 0, "Error Message");
}
}
EOF
}
jsuite(){
if [ -z "$1" ]; then
echo "Please provide JUnit Version (4 or 5) as argument" >&2
exit 1
fi
if [ "$1" == "4" ]; then
cat > src/TestSuite.java <<EOF
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ $test_name.class })
public class TestSuite {
}
EOF
elif [ "$1" == "5" ]; then
cat > src/TestSuite.java <<EOF
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
@SelectClasses({ $test_name.class })
@Suite
public class TestSuite {
}
EOF
else
echo "Please provide JUnit Version (4 or 5) as argument" >&2
exit 1
fi
}
base(){
mkdir -p bin lib src .vscode
cat > .vscode/settings.json <<EOF
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": ["lib/**/*.jar"]
}
EOF
}
base
opstring="45s:n:"
while getopts $opstring opt; do
case $opt in
n) export test_name=$OPTARG ;;
4) j4 ;;
5) j5 ;;
s) jsuite "$OPTARG" ;;
\?) echo "Invalid option: $OPTARG" ;;
esac
done
code .