Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit 66554d6

Browse files
docs: add comprehensive TESTING.md guide and update README testing section
- Created TESTING.md with test suite overview, running instructions, conventions (graph construction pattern, naming, null checks), coverage gap inventory (40 untested classes listed), and guide for writing new tests - Updated README Testing section to use Maven commands instead of manual javac/JUnit invocation, with link to TESTING.md - Added TESTING.md reference in Architecture overview paragraph
1 parent 3a90814 commit 66554d6

2 files changed

Lines changed: 166 additions & 16 deletions

File tree

README.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The tool was developed for research on **social network analysis** — specifica
6161

6262
## Architecture
6363

64-
GraphVisual consists of 145 source classes (~55,000+ lines of production code, 100,000+ total with tests), 57 graph analyzers, and a Bluetooth-to-graph data pipeline. See **[ARCHITECTURE.md](ARCHITECTURE.md)** and **[ALGORITHMS.md](ALGORITHMS.md)** for full details including the analyzer reference table, design patterns, and dependency map.
64+
GraphVisual consists of 145 source classes (~55,000+ lines of production code, 100,000+ total with tests), 57 graph analyzers, and a Bluetooth-to-graph data pipeline. See **[ARCHITECTURE.md](ARCHITECTURE.md)**, **[ALGORITHMS.md](ALGORITHMS.md)**, and **[TESTING.md](TESTING.md)** for full details including the analyzer reference table, design patterns, dependency map, and testing guide.
6565

6666
```
6767
Gvisual/src/
@@ -272,27 +272,21 @@ All thresholds are adjustable at runtime via the Category Panel sliders.
272272

273273
## Testing
274274

275-
Run tests with JUnit 4:
275+
The test suite includes **106 test classes** with **2,100+ tests** covering analyzers, exporters, layouts, and utilities.
276276

277277
```bash
278-
cd Gvisual
279-
mkdir -p build/test/classes
280-
281-
# Download JUnit (if not present)
282-
curl -sL -o lib/test/junit-4.13.2.jar \
283-
https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
284-
curl -sL -o lib/test/hamcrest-core-1.3.jar \
285-
https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
278+
# Run all tests
279+
mvn test
286280

287-
# Compile and run
288-
find test -name '*.java' > test-sources.txt
289-
javac -cp "build/classes:$(find lib -name '*.jar' | tr '\n' ':')" \
290-
-d build/test/classes @test-sources.txt
281+
# Run a single test class
282+
mvn test -Dtest=BipartiteAnalyzerTest
291283

292-
java -cp "build/classes:build/test/classes:$(find lib -name '*.jar' | tr '\n' ':')" \
293-
org.junit.runner.JUnitCore app.UtilMethodsTest gvisual.EdgeTest
284+
# Run a specific method
285+
mvn test -Dtest=BipartiteAnalyzerTest#testMaximumMatchingCompleteBipartite
294286
```
295287

288+
See **[TESTING.md](TESTING.md)** for the full testing guide: conventions, coverage gaps, and how to write new tests.
289+
296290
## Maven / GitHub Packages
297291

298292
GraphVisual is published to [GitHub Packages](https://github.com/sauravbhattacharya001/GraphVisual/packages) as a Maven artifact. You can use it as a library dependency or download the fat JAR directly.

TESTING.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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

Comments
 (0)