测试用例执行成功后Serenity BDD报告未生成问题求助
Hi AnnieC, let's work through your problem step by step to get those Serenity reports generating properly, both locally in Eclipse and on Jenkins.
1. Critical Version Compatibility Issue
The first red flag is your version mismatch between Serenity core and the Serenity-JBehave integration:
- You're using
serenity.version=1.8.21butserenity.jbehave.version=1.35
Serenity-JBehave versions are tightly coupled to the core Serenity version. For Serenity 1.8.x, you should use a 1.8.x version of serenity-jbehave (e.g., 1.8.30, the latest in the 1.8.x line). Using a mismatched version like 1.35 will break the report generation pipeline, as the integration won't properly communicate with core Serenity libraries.
Update your pom.xml to align these versions:
<properties> <serenity.version>1.8.30</serenity.version> <serenity.jbehave.version>1.8.30</serenity.version> <!-- Keep other versions as is unless you need to update them --> </properties>
2. Fix Serenity Properties Configuration
Your serenity.properties has two issues that might block report generation:
- The
serenity.test.rootvalue has quotes and a space (Java package names can't have spaces!). If your test package isnet.bddproject(or similar), remove the quotes and fix the package name:serenity.test.root = net.bddproject - The
serenity.outputDirectorysetting changes where reports are saved, but I'd recommend removing this line first to use the defaulttarget/site/serenitydirectory. Get basic reports working first, then adjust the path if needed.
3. Verify Maven Build Goals & Plugin Configuration
Correct Build Goal
For Serenity-JBehave projects, the standard build goal to run tests and generate reports is:
clean verify
The serenity:aggregate goal is usually included automatically by the Serenity Maven plugin when you run verify, so adding it explicitly might cause conflicts. Try running just clean verify in Eclipse first.
Check Failsafe Plugin Configuration
Ensure your maven-failsafe-plugin is configured to pick up JBehave test classes:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.18</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <includes> <include>**/*Stories.java</include> </includes> </configuration> </execution> </executions> </plugin>
Make sure your test classes (the ones that run JBehave stories) follow the *Stories.java naming pattern.
Add Serenity JBehave Maven Plugin
You might be missing the plugin that ties JBehave test execution to Serenity's report generation. Add this to your pom.xml:
<plugin> <groupId>net.serenity-bdd.maven.plugins</groupId> <artifactId>serenity-jbehave-maven-plugin</artifactId> <version>${serenity.jbehave.version}</version> <executions> <execution> <id>stories</id> <phase>integration-test</phase> <goals> <goal>run-stories-as-tests</goal> </goals> </execution> </executions> </plugin>
4. Ensure Tests Are Actually Executing
The empty index.html in target/jbehave/view suggests no test stories were executed or captured. Check your Eclipse console for lines like "Running net.bddproject.MyStories" or counts of scenarios/steps run. If no tests run:
- Verify story files are in
src/test/resources/stories - Ensure your test classes correctly reference the story files
- Confirm step definitions are annotated with
@Given,@When,@Thenand match story syntax
5. Jenkins Configuration Fixes
Once local reports work:
- Push your fixed pom.xml and
serenity.propertiesto Git so Jenkins pulls the updated code. - In Jenkins, update the "Publish HTML reports" step to point to the correct directory:
- Default path:
target/site/serenity - If using a custom path: use your
serenity.outputDirectoryvalue
- Default path:
- Ensure Jenkins has read/write permissions to the workspace directory (file system permissions can block report generation).
Key Questions Answered
- Version issue? Yes, the mismatched Serenity core and Serenity-JBehave versions are a major cause of your problem.
- Manual report path configuration? Yes, you can use
serenity.outputDirectory, but get default reports working first before customizing. - Will Jenkins generate reports if Eclipse does? Yes, once your local build works, Jenkins (pulling the same code) will generate reports too, as long as build steps and paths are configured correctly.
Don't hesitate to dig into Maven build logs for subtle errors—sometimes the issue is a missing dependency or misnamed file that's easy to overlook.
内容的提问来源于stack exchange,提问作者AnnieC

