|
| 1 | +# Testing Guide |
| 2 | + |
| 3 | +This document covers GraphVisual's test suite: how to run tests, conventions to follow when writing new tests, and the architecture of the testing infrastructure. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Run all tests |
| 9 | +mvn test |
| 10 | + |
| 11 | +# Run a single test class |
| 12 | +mvn test -Dtest=BipartiteAnalyzerTest |
| 13 | + |
| 14 | +# Run a specific test method |
| 15 | +mvn test -Dtest=BipartiteAnalyzerTest#testMaximumMatchingCompleteBipartite |
| 16 | + |
| 17 | +# Run tests matching a pattern |
| 18 | +mvn test -Dtest="Graph*Test" |
| 19 | + |
| 20 | +# Run with verbose output |
| 21 | +mvn test -Dsurefire.useFile=false |
| 22 | +``` |
| 23 | + |
| 24 | +## Suite Overview |
| 25 | + |
| 26 | +| Metric | Value | |
| 27 | +|--------|-------| |
| 28 | +| Test classes | 106 (+ 2 in `app/`) | |
| 29 | +| Total tests | ~2,100+ | |
| 30 | +| Framework | JUnit 4 | |
| 31 | +| Source directory | `Gvisual/test/` | |
| 32 | +| Coverage areas | Analyzers, exporters, layouts, utilities, GUI controllers | |
| 33 | + |
| 34 | +The tests are configured via Maven Surefire in `pom.xml`: |
| 35 | + |
| 36 | +```xml |
| 37 | +<testSourceDirectory>Gvisual/test</testSourceDirectory> |
| 38 | +``` |
| 39 | + |
| 40 | +## Directory Structure |
| 41 | + |
| 42 | +``` |
| 43 | +Gvisual/test/ |
| 44 | +├── gvisual/ # 106 test classes for core library |
| 45 | +│ ├── ArticulationPointAnalyzerTest.java |
| 46 | +│ ├── BipartiteAnalyzerTest.java |
| 47 | +│ ├── ... |
| 48 | +│ └── TopologicalSortAnalyzerTest.java |
| 49 | +└── app/ # 2 test classes for data pipeline |
| 50 | + ├── ThresholdConfigTest.java |
| 51 | + └── UtilTest.java |
| 52 | +``` |
| 53 | + |
| 54 | +## Test Conventions |
| 55 | + |
| 56 | +### Graph Construction Pattern |
| 57 | + |
| 58 | +All analyzer tests follow a consistent pattern for building test graphs: |
| 59 | + |
| 60 | +```java |
| 61 | +private Graph<String, Edge> graph; |
| 62 | + |
| 63 | +@Before |
| 64 | +public void setUp() { |
| 65 | + graph = new UndirectedSparseGraph<String, Edge>(); // or DirectedSparseGraph |
| 66 | +} |
| 67 | + |
| 68 | +private Edge addEdge(String v1, String v2, String type) { |
| 69 | + Edge e = new Edge(type, v1, v2); |
| 70 | + e.setLabel(v1 + "-" + v2); |
| 71 | + graph.addEdge(e, v1, v2); |
| 72 | + return e; |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +Use `addEdge()` helpers to keep tests readable. The `type` parameter maps to `EdgeType` values (e.g., `"f"` for friends, `"c"` for classmates). |
| 77 | + |
| 78 | +### Test Categories |
| 79 | + |
| 80 | +Tests fall into these categories: |
| 81 | + |
| 82 | +1. **Happy path** — Standard inputs with known correct results |
| 83 | +2. **Edge cases** — Empty graphs, single vertices, disconnected components |
| 84 | +3. **Null/invalid input** — Verify `IllegalArgumentException` on null graphs |
| 85 | +4. **Algorithmic correctness** — Mathematical properties that must hold (e.g., chromatic number ≤ max degree + 1, Euler paths require 0 or 2 odd-degree vertices) |
| 86 | +5. **Large inputs** — Performance regression tests on graphs with hundreds of vertices |
| 87 | + |
| 88 | +### Naming Convention |
| 89 | + |
| 90 | +Test methods use descriptive names: |
| 91 | + |
| 92 | +```java |
| 93 | +@Test |
| 94 | +public void testMaximumMatchingCompleteBipartite() { ... } |
| 95 | + |
| 96 | +@Test(expected = IllegalArgumentException.class) |
| 97 | +public void testNullGraphThrows() { ... } |
| 98 | + |
| 99 | +@Test |
| 100 | +public void testEmptyGraphReturnsEmptyResult() { ... } |
| 101 | +``` |
| 102 | + |
| 103 | +### Null Checks |
| 104 | + |
| 105 | +Every analyzer must reject null graphs. Include this test: |
| 106 | + |
| 107 | +```java |
| 108 | +@Test(expected = IllegalArgumentException.class) |
| 109 | +public void testNullGraphThrows() { |
| 110 | + new MyAnalyzer(null); |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +### Summary Output |
| 115 | + |
| 116 | +Analyzers provide `generateSummary()` for human-readable output. Test it: |
| 117 | + |
| 118 | +```java |
| 119 | +@Test |
| 120 | +public void testSummaryNotEmpty() { |
| 121 | + // ... build graph and run analysis ... |
| 122 | + String summary = analyzer.generateSummary(); |
| 123 | + assertNotNull(summary); |
| 124 | + assertFalse(summary.isEmpty()); |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## Classes Without Tests |
| 129 | + |
| 130 | +The following 40 source classes in `gvisual/` do not have dedicated test classes. Contributions welcome: |
| 131 | + |
| 132 | +**Exporters:** `AdjacencyListExporter`, `CentralityRadarExporter`, `DimacsExporter`, `GraphDiffHtmlExporter`, `GraphMatrixExporter`, `GraphStorytellerExporter`, `GraphTimelineExporter`, `NetworkFlowExporter`, `TikzExporter` |
| 133 | + |
| 134 | +**GUI Controllers:** `ArticulationPanelController`, `CentralityPanelController`, `CommunityPanelController`, `EgoPanelController`, `ExportActions`, `MSTPanelController`, `PathPanelController`, `ResiliencePanelController`, `StatsPanel`, `ToolbarBuilder`, `Main`, `RandomGraphDialog` |
| 135 | + |
| 136 | +**Analyzers:** `GraphComplementAnalyzer`, `GraphCompressor`, `GraphDegreeSequenceRandomizer`, `GraphDrawingQualityAnalyzer`, `GraphHealthChecker`, `GraphLayoutComparer`, `GraphMotifFinder`, `GraphProductCalculator`, `GraphRegularityAnalyzer`, `GraphSpectrumAnalyzer`, `GraphStatsDashboard`, `GraphVoronoiPartitioner` |
| 137 | + |
| 138 | +**Utilities/Models:** `AdjacencyMatrixHeatmap`, `AnalysisResult`, `EdgeType`, `GraphRenderers`, `QuadTree`, `RandomGraphGenerator`, `SpectralLayout` |
| 139 | + |
| 140 | +## Writing New Tests |
| 141 | + |
| 142 | +1. Create `Gvisual/test/gvisual/YourClassTest.java` in the `gvisual` package |
| 143 | +2. Use `@Before` to initialize a fresh graph — do not share state between tests |
| 144 | +3. Cover: null input, empty graph, single vertex, small known graph, algorithmic invariants |
| 145 | +4. Keep tests deterministic — avoid `Math.random()` without a fixed seed |
| 146 | +5. Use `assertEquals(expected, actual, delta)` for floating-point comparisons (use `1e-9` tolerance) |
| 147 | +6. Run `mvn test -Dtest=YourClassTest` to verify before committing |
| 148 | + |
| 149 | +## CI Integration |
| 150 | + |
| 151 | +Tests run automatically via GitHub Actions on every push and PR. See `.github/workflows/ci.yml` for the workflow configuration. The CI pipeline: |
| 152 | + |
| 153 | +1. Checks out the code |
| 154 | +2. Sets up JDK 11 |
| 155 | +3. Runs `mvn test` with Surefire |
| 156 | +4. Reports failures in the PR checks |
0 commit comments