blob: b681fdb5180823c3e05dae8814548b30486e4033 (
plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# DS-Sim Test Infrastructure
## Overview
This document describes the current test infrastructure and available test utilities.
## Test Classes Location
### Unit Tests (`src/test/java/`)
- `core/` - Core component tests
- `VSMessageTest.java` - Message handling tests
- `VSTaskTest.java` - Task scheduling tests
- `events/` - Event system tests
- `VSAbstractEventTest.java` - Event framework tests
- `VSRegisteredEventsTest.java` - Event registration tests
- `implementations/` - Specific event tests
- `protocols/` - Protocol tests
- `VSAbstractProtocolTest.java` - Protocol framework tests
- `implementations/` - Specific protocol tests
### Test Utilities (`src/main/java/testing/`)
#### Core Classes
- `HeadlessSimulationRunner.java` - Main headless test runner
- `LogCapture.java` - Captures simulation logs for verification
- `SimulationResult.java` - Contains test execution results
- `ProtocolVerifier.java` - Verifies protocol behavior via logs
#### Test Runners
- `CleanHeadlessRunner.java` - Filters GUI errors from output
- `ProtocolTestRunnerWithLogs.java` - Shows detailed logs
- `SimpleProtocolTestRunner.java` - Basic test execution
- `QuietProtocolTestRunner.java` - Minimal output runner
#### Support Classes
- `DummySimulatorFrame.java` - Mock frame for headless mode
- `LogEntry.java`, `LogType.java` - Log data structures
- `VerificationRule.java`, `RuleResult.java` - Verification framework
## Maven Configuration
### Test Execution
```xml
<includes>
<include>**/core/*Test.java</include>
<include>**/events/**/*Test.java</include>
<include>**/protocols/VSAbstractProtocolTest.java</include>
<include>**/protocols/implementations/VSPingPongProtocolTest.java</include>
</includes>
<excludes>
<exclude>**/testing/**/*Test.java</exclude>
</excludes>
```
### Dependencies
- JUnit Jupiter 5.10.0
- Mockito 5.3.1
- SLF4J + Logback for logging
## Running Tests
### Command Line
```bash
# All tests
mvn test
# Specific test
mvn test -Dtest=VSMessageTest
# Pattern
mvn test -Dtest="*Event*"
```
### IDE
- Import as Maven project
- Run test classes/packages directly
- Use IDE test runners for debugging
## Test Categories
### 1. Fast Unit Tests (Default)
- No external dependencies
- No GUI components
- Millisecond execution time
- Run in CI/CD
### 2. Integration Tests (Excluded)
- Require saved simulations
- May create GUI components
- Longer execution time
- Manual execution only
### 3. GUI Tests (Excluded)
- Require display
- Test UI components
- Manual execution only
## Writing New Tests
### Unit Test Template
```java
package core;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class MyComponentTest {
private MyComponent component;
@BeforeEach
void setUp() {
component = new MyComponent();
}
@Test
void testBasicFunctionality() {
// Given
String input = "test";
// When
String result = component.process(input);
// Then
assertEquals("expected", result);
}
}
```
### Protocol Test Template
```java
@BeforeEach
void setUp() {
mockProcess = mock(VSInternalProcess.class);
mockTaskManager = mock(VSTaskManager.class);
when(mockProcess.getTaskManager()).thenReturn(mockTaskManager);
protocol = new MyProtocol();
protocol.init(mockProcess);
}
```
## Limitations
1. **GUI Coupling**: Many components require GUI initialization
2. **Headless Mode**: Protocol simulations produce GUI errors
3. **Serialization**: Saved simulations may have version issues
## Future Improvements
See `docs/gui-decoupling-plan.md` for proposed architecture changes that would enable comprehensive headless testing.
|