1
|
|
package junit.extensions.abbot;
|
2
|
|
|
3
|
|
import java.io.File;
|
4
|
|
import java.util.*;
|
5
|
|
|
6
|
|
import junit.framework.*;
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
public class ScriptTestSuiteTest extends TestCase {
|
12
|
|
|
13
|
|
private static int runs;
|
14
|
|
public static class MyScriptFixture extends ScriptFixture {
|
15
|
12
|
public MyScriptFixture(String filename) {
|
16
|
12
|
super(filename);
|
17
|
|
}
|
18
|
12
|
protected void runTest() throws Throwable {
|
19
|
12
|
++runs;
|
20
|
|
}
|
21
|
|
}
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
|
26
|
1
|
public void testDerivedClass() throws Throwable {
|
27
|
1
|
runs = 0;
|
28
|
1
|
Test suite = new ScriptTestSuite(MyScriptFixture.class, "src/example");
|
29
|
1
|
suite.run(new TestResult());
|
30
|
1
|
assertTrue("Derived test fixture class was never run", runs != 0);
|
31
|
|
}
|
32
|
|
|
33
|
|
|
34
|
1
|
public void testGenerateFilenames() throws Throwable {
|
35
|
1
|
File tmp = File.createTempFile(getName(), "-dummy");
|
36
|
1
|
File tmpdir = tmp.getParentFile();
|
37
|
1
|
tmp.delete();
|
38
|
1
|
File[] files = tmpdir.listFiles();
|
39
|
1
|
for (int i=0;i < files.length;i++) {
|
40
|
56
|
if (files[i].getName().startsWith(getName())
|
41
|
|
&& files[i].getName().endsWith(".tst")) {
|
42
|
0
|
files[i].delete();
|
43
|
|
}
|
44
|
|
}
|
45
|
|
|
46
|
1
|
File f1 = File.createTempFile(getName(), ".tst");
|
47
|
1
|
f1.deleteOnExit();
|
48
|
1
|
File f2 = File.createTempFile(getName(), ".tst");
|
49
|
1
|
f2.deleteOnExit();
|
50
|
1
|
File f3 = File.createTempFile(getName(), ".tst");
|
51
|
1
|
f3.deleteOnExit();
|
52
|
|
|
53
|
1
|
String[] flist = ScriptTestSuite.
|
54
|
|
findFilenames(f1.getParentFile().getAbsolutePath(), false);
|
55
|
1
|
List list = new ArrayList();
|
56
|
1
|
for (int i=0;i < flist.length;i++) {
|
57
|
46
|
String fn = flist[i];
|
58
|
46
|
if (fn.indexOf(getName()) != -1 && fn.endsWith(".tst")) {
|
59
|
3
|
list.add(fn);
|
60
|
|
}
|
61
|
|
}
|
62
|
1
|
assertEquals("Wrong number of files", 3, list.size());
|
63
|
1
|
assertTrue("Missing f1", list.contains(f1.getAbsolutePath()));
|
64
|
1
|
assertTrue("Missing f2", list.contains(f2.getAbsolutePath()));
|
65
|
1
|
assertTrue("Missing f3", list.contains(f3.getAbsolutePath()));
|
66
|
|
}
|
67
|
|
|
68
|
2
|
public ScriptTestSuiteTest(String name) {
|
69
|
2
|
super(name);
|
70
|
|
}
|
71
|
|
|
72
|
0
|
public static void main(String[] args) {
|
73
|
0
|
TestHelper.runTests(args, ScriptTestSuiteTest.class);
|
74
|
|
}
|
75
|
|
}
|
76
|
|
|