AssertJ社区贡献指南:如何参与开源测试库开发

张开发
2026/4/10 1:24:44 15 分钟阅读
AssertJ社区贡献指南:如何参与开源测试库开发
AssertJ社区贡献指南如何参与开源测试库开发【免费下载链接】assertjFluent testing assertions for Java and the JVM项目地址: https://gitcode.com/gh_mirrors/as/assertjAssertJ是一款强大的Java测试断言库它提供了流畅的API帮助开发者编写更易读、更易维护的测试代码。作为开源项目AssertJ的成长离不开社区的积极贡献。本文将为你提供一份详尽的社区贡献指南助你轻松参与到这个优秀测试库的开发中。贡献前的准备工作在开始贡献之前确保你的开发环境满足以下要求使用JDK 25或更高版本构建项目配置代码格式化工具使用项目提供的Eclipse格式化配置IntelliJ用户可通过Eclipse代码格式化适配器插件导入代码贡献规范代码风格与文档要求为每个断言方法编写完整的Javadoc包含代码示例成功和失败的断言使用JUnit 5测试类和方法采用包私有可见性测试类命名遵循AssertClass_assertion_Test格式测试方法命名采用下划线风格成功的断言测试以should_pass_xxx开头失败的断言测试以should_fail_xxx开头在每个测试中使用GIVENWHENTHEN步骤THEN步骤优先使用BDDAssertions.then使用AssertionUtil.expectAssertionError测试预期的AssertionError测试编写示例一个良好的单元测试示例import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; class OptionalAssert_containsInstanceOf_Test extends BaseTest { Test void should_fail_if_optional_is_empty() { // GIVEN OptionalObject actual Optional.empty(); // WHEN var assertionError expectAssertionError(() - assertThat(actual).containsInstanceOf(Object.class)); // THEN then(assertionError).hasMessage(shouldBePresent(actual).create()); } Test void should_pass_if_optional_contains_required_type() { // GIVEN OptionalString optional Optional.of(something); // WHEN/THEN then(optional).containsInstanceOf(String.class); } }Javadoc编写规范良好的Javadoc应包含断言描述、代码示例、参数说明、异常描述和since标签。以下是一个优秀的Javadoc示例/** * Verifies that the actual {code CharSequence} contains all the given strings bin the given order/b. * p * Example: * * precode classjava String book { title:A Game of Thrones, author:George Martin}; * * // this assertion succeeds ... * assertThat(book).containsSequence({, title, A Game of Thrones, }); * * // ... but this one fails as author must come after A Game of Thrones * assertThat(book).containsSequence({, author, A Game of Thrones, }); /code/pre * * param values the Strings to look for, in order. * return {code this} assertion object. * throws NullPointerException if the given values is {code null}. * throws IllegalArgumentException if the given values is empty. * throws AssertionError if the actual {code CharSequence} is {code null}. * throws AssertionError if the actual {code CharSequence} does not contain all the given strings bin the given order/b. * since 2.1.0 / 3.1.0 */提交贡献的步骤1. 准备代码在提交PR前执行./mvnw spotless:apply确保代码格式正确执行./mvnw clean verify确保所有测试通过2. 提交PR将PR基于main分支进行rebase不要合并我们倾向于通过压缩所有提交并rebase到main来集成PR如果PR有分歧并需要获取更新的main提交请rebase到main但不要将main合并到你的PR分支二进制兼容性注意事项尽量保持二进制兼容性以下更改通常是安全的重写方法、构造函数和初始化器的主体重写以前抛出异常的代码以不再抛出添加字段、方法和构造函数删除声明为私有的元素重新排序字段、方法和构造函数在类层次结构中向上移动方法重新排序类或接口中的直接超接口列表在类型层次结构中插入新的类或接口类型添加泛型因为编译器会擦除它们更新包私有元素其他更改可能会影响二进制兼容性这些不会被自动拒绝但我们会仔细评估每个更改的利弊。法律声明项目许可证Apache License Version 2.0作为贡献者你提交的贡献必须是你100%原创的内容你必须对提交的贡献拥有必要的权利。这意味着如果你受雇你已获得雇主的必要许可你贡献的任何内容将根据项目许可证提供开始你的贡献之旅现在你已经了解了AssertJ的贡献规范是时候开始你的贡献之旅了无论是修复bug、添加新功能还是改进文档你的每一份贡献都将帮助AssertJ变得更好。克隆仓库开始贡献吧git clone https://gitcode.com/gh_mirrors/as/assertj加入AssertJ社区一起打造更强大的Java测试断言库【免费下载链接】assertjFluent testing assertions for Java and the JVM项目地址: https://gitcode.com/gh_mirrors/as/assertj创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

更多文章