html_reporting/
html_reporting.rs1use rust_test_harness::{
14 test, run_tests_with_config, TestConfig
15};
16use std::time::Duration;
17
18fn main() {
19 println!("๐งช HTML Reporting Example");
20 println!("=========================");
21 println!();
22
23 println!("๐ Example 1: Basic HTML Report");
25 println!("Generating basic HTML report...");
26
27 test("basic_passing_test", |_| Ok(()));
29 test("another_passing_test", |_| Ok(()));
30
31 let config = TestConfig {
32 html_report: Some("basic_report.html".to_string()),
33 skip_hooks: None,
34 ..Default::default()
35 };
36
37 let result = run_tests_with_config(config);
38 println!("โ
Basic report generated with exit code: {}", result);
39 println!();
40
41 println!("๐ Example 2: Mixed Results Report");
43 println!("Generating report with pass/fail/skip results...");
44
45 test("successful_test", |_| Ok(()));
47 test("failing_test", |_| Err("intentional failure".into()));
48 test("skipped_test", |_| Ok(()));
49
50 let config = TestConfig {
51 html_report: Some("mixed_results_report.html".to_string()),
52 skip_hooks: None,
53 ..Default::default()
54 };
55
56 let result = run_tests_with_config(config);
57 println!("โ
Mixed results report generated with exit code: {}", result);
58 println!();
59
60 println!("๐ Example 3: Rich Metadata Report");
62 println!("Generating report with tags, timeouts, and Docker...");
63
64 test("tagged_test", |_| Ok(()));
66 test("timeout_test", |_| Ok(()));
67 test("docker_integration_test", |_| Ok(()));
68 test("database_connection_test", |_| Ok(()));
69 test("api_endpoint_test", |_| Ok(()));
70
71 let config = TestConfig {
75 html_report: Some("rich_metadata_report.html".to_string()),
76 skip_hooks: None,
77 ..Default::default()
78 };
79
80 let result = run_tests_with_config(config);
81 println!("โ
Rich metadata report generated with exit code: {}", result);
82 println!(" ๐ 5 tests with different types (tags, timeouts, Docker, DB, API)");
83 println!();
84
85 println!("๐ Example 4: Large Test Suite Report");
87 println!("Generating report for many tests with realistic mixed results...");
88
89 for i in 0..25 {
91 match i {
92 0..=15 => {
94 test(&format!("large_suite_test_{}", i), |_| Ok(()));
95 },
96 16..=19 => {
98 test(&format!("large_suite_test_{}", i), move |_| {
99 Err(format!("Test {} failed due to assertion error", i).into())
100 });
101 },
102 20..=22 => {
104 test(&format!("large_suite_test_{}", i), move |_| {
105 std::thread::sleep(Duration::from_millis(50));
107 Err(format!("Test {} failed due to timeout (exceeded 30ms limit)", i).into())
108 });
109 },
110 23 => {
112 test(&format!("large_suite_test_{}", i), move |_| {
113 panic!("Test {} panicked due to unexpected condition", i);
114 });
115 },
116 24 => {
118 test(&format!("large_suite_test_{}", i), |_| {
119 Err("Test skipped due to missing dependencies".into())
120 });
121 },
122 _ => unreachable!(),
123 }
124 }
125
126 let config = TestConfig {
127 html_report: Some("large_suite_report.html".to_string()),
128 skip_hooks: None,
129 ..Default::default()
130 };
131
132 let result = run_tests_with_config(config);
133 println!("โ
Large suite report generated with exit code: {}", result);
134 println!(" ๐ 16 tests passed, 7 failed (4 errors + 3 timeouts), 1 panic, 1 skipped");
135 println!();
136
137 println!("๐ Example 5: Environment Variable Configuration");
139 println!("Setting TEST_HTML_REPORT environment variable...");
140
141 std::env::set_var("TEST_HTML_REPORT", "env_var_report.html");
143
144 test("env_test", |_| Ok(()));
146
147 let config = TestConfig::default();
148 println!("๐ Config HTML report path: {:?}", config.html_report);
149
150 let result = run_tests_with_config(config);
151 println!("โ
Environment variable report generated with exit code: {}", result);
152 println!();
153
154 println!("๐ Example 6: Performance Testing Report");
156 println!("Generating report for performance tests with realistic scenarios...");
157
158 for i in 0..15 {
160 match i {
161 0..=8 => {
163 test(&format!("perf_test_{}", i), |_| {
164 std::thread::sleep(Duration::from_millis(5));
166 Ok(())
167 });
168 },
169 9..=11 => {
171 test(&format!("perf_test_{}", i), |_| {
172 std::thread::sleep(Duration::from_millis(20));
174 Ok(())
175 });
176 },
177 12..=13 => {
179 test(&format!("perf_test_{}", i), |_| {
180 std::thread::sleep(Duration::from_millis(50));
182 Ok(())
183 });
184 },
185 14 => {
187 test(&format!("perf_test_{}", i), |_| {
188 std::thread::sleep(Duration::from_millis(100));
190 Err("Performance test exceeded expected time limit (50ms)".into())
191 });
192 },
193 _ => unreachable!(),
194 }
195 }
196
197 let config = TestConfig {
198 html_report: Some("performance_report.html".to_string()),
199 max_concurrency: Some(4),
200 skip_hooks: None,
201 ..Default::default()
202 };
203
204 let result = run_tests_with_config(config);
205 println!("โ
Performance report generated with exit code: {}", result);
206 println!(" ๐ 14 tests passed, 1 failed (timeout)");
207 println!();
208
209 println!("๐ HTML Reporting Examples Complete!");
211 println!("=====================================");
212 println!();
213 println!("Generated HTML reports (stored in target/test-reports/):");
214 println!(" ๐ basic_report.html - Basic functionality");
215 println!(" ๐ mixed_results_report.html - Pass/fail/skip results");
216 println!(" ๐ rich_metadata_report.html - Rich test metadata");
217 println!(" ๐ large_suite_report.html - Large test suite");
218 println!(" ๐ env_var_report.html - Environment variable config");
219 println!(" ๐ performance_report.html - Performance testing");
220 println!();
221 println!("๐ All reports are automatically organized in target/test-reports/");
222 println!();
223 println!("๐ HTML Report Features:");
224 println!(" ๐ฝ Expandable test details - Click any test to expand");
225 println!(" ๐ Real-time search - Search by name, status, or tags");
226 println!(" โจ๏ธ Keyboard shortcuts - Ctrl+F (search), Ctrl+A (expand all)");
227 println!(" ๐จ Auto-expand failed - Failed tests automatically expand");
228 println!(" ๐ฑ Responsive design - Works on all devices");
229 println!();
230 println!("๐ก Usage Tips:");
231 println!(" โข Open any .html file in your web browser");
232 println!(" โข Use Ctrl+F to search for specific tests");
233 println!(" โข Click test headers to expand/collapse details");
234 println!(" โข Failed tests are automatically expanded for visibility");
235 println!(" โข Reports work great in CI/CD pipelines and team sharing");
236 println!(" โข All reports are neatly organized in target/test-reports/");
237 println!();
238 println!("๐ง Configuration Options:");
239 println!(" โข Set TEST_HTML_REPORT environment variable");
240 println!(" โข Use TestConfig.html_report for programmatic control");
241 println!(" โข Combine with other config options (filtering, concurrency)");
242 println!(" โข Reports automatically go to target/test-reports/ for clean organization");
243}