Skip to content

Commit e9d1953

Browse files
committed
add allure report
1 parent d2c7b0c commit e9d1953

24 files changed

Lines changed: 1174 additions & 110 deletions

File tree

.github/workflows/build.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,70 @@ jobs:
1717
build:
1818
name: "Build"
1919
runs-on: ubuntu-latest
20+
env:
21+
ALLURE_DUMP_NAME: allure-results-build
2022
steps:
2123
- uses: actions/checkout@v6
2224

25+
- uses: actions/setup-node@v6
26+
with:
27+
node-version: '20'
28+
2329
- name: "Set up JDK"
2430
uses: actions/setup-java@v5
2531
with:
2632
distribution: 'zulu'
2733
java-version: 21
2834

35+
- name: "Setup Gradle"
36+
uses: gradle/actions/setup-gradle@v6
37+
with:
38+
gradle-version: 'wrapper'
39+
2940
- name: "Build with Gradle"
3041
run: ./gradlew build -x test --scan
3142

32-
- name: "Run tests"
43+
- name: "Run tests with Allure"
3344
if: always()
34-
run: ./gradlew --no-build-cache cleanTest test
45+
run: npx -y allure@3 run --config ./allurerc.yml --dump="${{ env.ALLURE_DUMP_NAME }}" -- ./gradlew --no-build-cache cleanTest test
46+
47+
- name: "Upload Allure dump"
48+
if: always()
49+
uses: actions/upload-artifact@v5
50+
with:
51+
name: ${{ env.ALLURE_DUMP_NAME }}
52+
path: ./${{ env.ALLURE_DUMP_NAME }}.zip
53+
if-no-files-found: error
54+
55+
report:
56+
needs: build
57+
name: "Build Allure Report"
58+
runs-on: ubuntu-latest
59+
if: always()
60+
permissions:
61+
contents: read
62+
pull-requests: write
63+
checks: write
64+
steps:
65+
- uses: actions/checkout@v6
66+
67+
- uses: actions/setup-node@v6
68+
with:
69+
node-version: '20'
70+
71+
- name: "Download Allure dumps"
72+
uses: actions/download-artifact@v6
73+
with:
74+
pattern: allure-results-*
75+
path: ./
76+
merge-multiple: true
77+
78+
- name: "Generate Allure report"
79+
run: npx -y allure@3 generate --config ./allurerc.yml --dump="allure-results-*.zip" --output=./build/allure-report
80+
81+
- name: "Post Allure summary"
82+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
83+
uses: allure-framework/allure-action@v0
84+
with:
85+
report-directory: ./build/allure-report
86+
github-token: ${{ secrets.GITHUB_TOKEN }}

AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Project Guide
2+
3+
Use [Allure Agent Mode](docs/allure-agent-mode.md) for all test-related work in this repository.
4+
5+
- Read `docs/allure-agent-mode.md` before designing, writing, reviewing, validating, debugging, or enriching tests.
6+
- Run test-executing commands through `allure run`, including smoke checks after small edits.
7+
- Use `./gradlew` for repo-local test commands and scope runs to the smallest relevant module or task.
8+
- If agent-mode output is missing or incomplete, debug that first rather than relying on console-only conclusions.

allure-java-commons-test/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ dependencies {
66
api("org.apache.commons:commons-lang3")
77
api(project(":allure-java-commons"))
88
implementation("com.fasterxml.jackson.core:jackson-databind")
9+
testImplementation("org.junit.jupiter:junit-jupiter-api")
10+
testImplementation(project(":allure-junit-platform"))
11+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
912
}
1013

1114
tasks.jar {
@@ -15,3 +18,7 @@ tasks.jar {
1518
))
1619
}
1720
}
21+
22+
tasks.test {
23+
useJUnitPlatform()
24+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.test;
17+
18+
import io.qameta.allure.model.Label;
19+
import io.qameta.allure.model.Status;
20+
import io.qameta.allure.model.TestResult;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.util.List;
24+
25+
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
28+
class AllurePredicatesTest {
29+
30+
@Test
31+
void shouldMatchStatusAndLabels() {
32+
final TestResult result = new TestResult()
33+
.setStatus(Status.PASSED)
34+
.setLabels(List.of(new Label().setName("feature").setValue("attachments")));
35+
36+
assertTrue(AllurePredicates.hasStatus(Status.PASSED).test(result));
37+
assertTrue(AllurePredicates.hasLabel("feature", "attachments").test(result));
38+
assertFalse(AllurePredicates.hasStatus(Status.FAILED).test(result));
39+
assertFalse(AllurePredicates.hasLabel("feature", "steps").test(result));
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.test;
17+
18+
import io.qameta.allure.Allure;
19+
import io.qameta.allure.model.TestResult;
20+
import io.qameta.allure.model.TestResultContainer;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.io.ByteArrayInputStream;
24+
import java.nio.charset.StandardCharsets;
25+
import java.util.List;
26+
27+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertSame;
30+
31+
class AllureResultsWriterStubTest {
32+
33+
@Test
34+
void shouldStoreResultsContainersAndAttachments() {
35+
final AllureResultsWriterStub writer = new AllureResultsWriterStub();
36+
final TestResult testResult = new TestResult()
37+
.setUuid("test-uuid")
38+
.setName("demo");
39+
final TestResultContainer container = new TestResultContainer()
40+
.setUuid("container-uuid")
41+
.setChildren(List.of("test-uuid"));
42+
43+
Allure.step("Store a test result, its container, and an attachment", () -> {
44+
writer.write(testResult);
45+
writer.write(container);
46+
writer.write("payload.txt", new ByteArrayInputStream("payload".getBytes(StandardCharsets.UTF_8)));
47+
});
48+
49+
Allure.step("Verify the stub exposes the written runtime artifacts", () -> {
50+
assertSame(testResult, writer.getTestResultByName("demo"));
51+
assertEquals(List.of(container), writer.getTestResultContainersForTestResult(testResult));
52+
assertArrayEquals("payload".getBytes(StandardCharsets.UTF_8), writer.getAttachments().get("payload.txt"));
53+
});
54+
}
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.test;
17+
18+
import io.qameta.allure.Allure;
19+
import io.qameta.allure.model.Status;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
26+
class RunUtilsTest {
27+
28+
@Test
29+
void shouldCaptureFailureStatusWithinSyntheticTestContext() {
30+
final AllureResults results = Allure.step("Execute a synthetic test context that raises an assertion error", () ->
31+
RunUtils.runWithinTestContext(() -> {
32+
throw new AssertionError("boom");
33+
})
34+
);
35+
36+
Allure.step("Verify the captured synthetic test result is marked as failed", () -> {
37+
assertEquals(1, results.getTestResults().size());
38+
assertEquals(Status.FAILED, results.getTestResults().get(0).getStatus());
39+
assertTrue(results.getTestResults().get(0).getStatusDetails().getMessage().contains("boom"));
40+
});
41+
}
42+
43+
@Test
44+
void shouldAttachNestedRunArtifactsToOuterLifecycle() {
45+
final AllureResults results = Allure.step("Execute a nested synthetic run and capture its emitted attachments", () ->
46+
RunUtils.runWithinTestContext(() ->
47+
RunUtils.runWithinTestContext(() -> {
48+
})
49+
)
50+
);
51+
52+
Allure.addAttachment("nested-attachment-keys", String.join("\n", results.getAttachments().keySet()));
53+
Allure.step("Verify the outer lifecycle receives serialized artifacts from the nested run", () -> {
54+
assertFalse(results.getAttachments().isEmpty());
55+
assertTrue(results.getAttachments().values().stream()
56+
.map(bytes -> new String(bytes, java.nio.charset.StandardCharsets.UTF_8))
57+
.anyMatch(body -> body.contains("\"uuid\"")));
58+
});
59+
}
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.test;
17+
18+
import io.qameta.allure.Allure;
19+
import io.github.benas.randombeans.api.EnhancedRandom;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.concurrent.atomic.AtomicReference;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotSame;
26+
import static org.junit.jupiter.api.Assertions.assertSame;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
29+
class TestUtilitiesTest {
30+
31+
@Test
32+
void shouldGenerateStableThreadLocalRandomPerThread() throws Exception {
33+
final EnhancedRandom mainThread = ThreadLocalEnhancedRandom.current();
34+
final AtomicReference<EnhancedRandom> workerThread = new AtomicReference<>();
35+
final Thread thread = new Thread(() ->
36+
workerThread.set(ThreadLocalEnhancedRandom.current())
37+
);
38+
39+
Allure.step("Resolve thread-local random generators on two threads and compare their identities", () -> {
40+
thread.start();
41+
thread.join();
42+
Allure.addAttachment(
43+
"thread-local-random-identities",
44+
"main=" + System.identityHashCode(mainThread)
45+
+ "\nworker=" + System.identityHashCode(workerThread.get())
46+
);
47+
assertSame(mainThread, ThreadLocalEnhancedRandom.current());
48+
assertNotSame(mainThread, workerThread.get());
49+
});
50+
}
51+
52+
@Test
53+
void shouldGenerateExpectedRandomTestDataShapes() {
54+
final String name = TestData.randomName();
55+
final String id = TestData.randomId();
56+
final String value = TestData.randomString(16);
57+
58+
assertEquals(10, name.length());
59+
assertEquals(10, id.length());
60+
assertEquals(16, value.length());
61+
assertTrue(name.matches("[A-Za-z]+"));
62+
assertTrue(id.matches("[A-Za-z0-9]+"));
63+
assertTrue(value.matches("[A-Za-z0-9]+"));
64+
}
65+
}

allure-junit4-aspect/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ dependencies {
66
api(project(":allure-junit4"))
77
compileOnly("junit:junit:$junitVersion")
88
compileOnly("org.aspectj:aspectjrt")
9+
testImplementation("junit:junit:$junitVersion")
10+
testImplementation("org.junit.jupiter:junit-jupiter-api")
11+
testImplementation("org.aspectj:aspectjrt")
12+
testImplementation("org.mockito:mockito-core")
13+
testImplementation("org.slf4j:slf4j-simple")
14+
testImplementation(project(":allure-junit-platform"))
15+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
916
}
1017

1118
tasks.jar {
@@ -15,3 +22,7 @@ tasks.jar {
1522
))
1623
}
1724
}
25+
26+
tasks.test {
27+
useJUnitPlatform()
28+
}

0 commit comments

Comments
 (0)