-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestResultStatsExample.java
More file actions
82 lines (74 loc) · 3.16 KB
/
Copy pathTestResultStatsExample.java
File metadata and controls
82 lines (74 loc) · 3.16 KB
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
package ai.rhesis.sdk.examples;
import ai.rhesis.sdk.RhesisClient;
import ai.rhesis.sdk.entities.InsightsIdsResponse;
import ai.rhesis.sdk.entities.InsightsQuery;
import ai.rhesis.sdk.entities.InsightsResponse;
import java.util.List;
import java.util.Map;
public class TestResultStatsExample {
public static void main(String[] args) {
RhesisClient client = RhesisClient.builder().apiKey(System.getenv("RHESIS_API_KEY")).build();
// --- Overall test result counts ---
System.out.println("=== Test Result Count ===");
InsightsResponse overall =
client
.insights()
.get("test_result", List.of(), List.of("count", "pass_rate", "passed", "failed"), null);
for (Map<String, Object> row : overall.rows()) {
System.out.println(" " + row);
}
// --- Pass rates by requirement ---
System.out.println("\n=== Pass Rates by Requirement ===");
InsightsResponse byRequirement =
client
.insights()
.get("test_result", List.of("requirement"), List.of("count", "pass_rate"), null);
for (Map<String, Object> row : byRequirement.rows()) {
System.out.printf(
" %-25s count=%s pass_rate=%s%n",
row.get("requirement"), row.get("count"), row.get("pass_rate"));
}
// --- Pass rates by category ---
System.out.println("\n=== Pass Rates by Category ===");
InsightsResponse byCategory =
client
.insights()
.get("test_result", List.of("category"), List.of("count", "pass_rate"), null);
for (Map<String, Object> row : byCategory.rows()) {
System.out.printf(
" %-25s count=%s pass_rate=%s%n",
row.get("category"), row.get("count"), row.get("pass_rate"));
}
// --- Pass rates by topic ---
System.out.println("\n=== Pass Rates by Topic ===");
InsightsResponse byTopic =
client.insights().get("test_result", List.of("topic"), List.of("count", "pass_rate"), null);
for (Map<String, Object> row : byTopic.rows()) {
System.out.printf(
" %-25s count=%s pass_rate=%s%n",
row.get("topic"), row.get("count"), row.get("pass_rate"));
}
// --- Results from the last 6 months ---
System.out.println("\n=== Test Results (last 6 months) ===");
InsightsQuery recentQuery =
InsightsQuery.builder("test_result")
.groupBy(List.of("requirement"))
.measures(List.of("count", "pass_rate"))
.months(6)
.build();
InsightsResponse recent = client.insights().get(recentQuery);
for (Map<String, Object> row : recent.rows()) {
System.out.printf(
" %-25s count=%s pass_rate=%s%n",
row.get("requirement"), row.get("count"), row.get("pass_rate"));
}
// --- Get IDs of failed test results ---
System.out.println("\n=== Failed Test Result IDs ===");
InsightsIdsResponse failedIds = client.insights().ids("test_result", "fail", null);
System.out.println("Entity: " + failedIds.entity());
System.out.println("Failed IDs: " + failedIds.ids().size());
for (String id : failedIds.ids().subList(0, Math.min(5, failedIds.ids().size()))) {
System.out.println(" " + id);
}
}
}