Introduce AssertJ for testing
- Ngôn ngữ chính
- Java
- Star
- 3.1k
- Fork
- 1.6k
- Merge trung bình
- 3 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 33
Mô tả
### Describe the enhancement requested
AssertJ gives us readable, fluent assertions that make tests easier to write and failures easier to analyze. With JUnit's `assertEquals(expected, actual)` it's easy to mix up argument order, and you end up with confusing failure messages. AssertJ's `assertThat(actual).isEqualTo(expected)` reads naturally and always gets the order right. Additionally, it provides a lot of flexibility when asserting things.
Compound checks that need multiple JUnit assertions collapse into a single chain:
```
// JUnit
assertNotNull(list);
assertEquals(3, list.size());
assertTrue(list.contains("foo"));
```
```
// AssertJ
assertThat(list).hasSize(3).contains("foo");
```
When something fails, AssertJ tells you exactly what went wrong and makes debugging much easier, because the failure message usually contains enough details to understand the issue. For example, an assertion on a list would fail with `expected list to contain 'foo' but was ['bar', 'baz']`. JUnit assertions on the other hand would only contain `expected true but was false`.
It also covers cases where JUnit assertions are just clunky: exception messages, collection contents, map entries, string patterns, comparisons with custom comparators. All without needing Hamcrest matchers or custom helper methods.
I'm planning to add it as a project-wide test dependency so new tests can use it immediately. Existing tests don't need to be migrated, and we can move them over incrementally where it makes sense.
### Component(s)
_No response_
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Không có tệp hoặc bài kiểm thử nào được nêu. Hãy bắt đầu bằng cách tìm cấu hình dependency kiểm thử trên toàn dự án và kiểm tra cách các dependency kiểm thử hiện có được khai báo; được xem là hoàn tất khi AssertJ có thể được sử dụng cho các bài kiểm thử mới mà không cần di chuyển các bài kiểm thử hiện có và test build của dự án chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- testing
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 62/100