Add custom exception assertions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- java
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với phần “2.6.2 Custom Assertions” hiện có trong hướng dẫn AssertJ được liên kết và kiểm tra repository assertj-examples được liên kết để xem các ví dụ assertion hiện tại của nó. Xác nhận các assertion tùy chỉnh cho exception phù hợp với hệ thống phân cấp lớp hiện có như thế nào, sau đó ghi lại một ví dụ bao quát message của exception và các trường chi tiết ở cả hai vị trí.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Currently, the documentation shows how to extend an assertion in 2.6.2 Custom Assertions but there is no documentation for custom exception asserts, which seems to use a slightly different mechanism with some other class hierarchy.
It would be nice to include this in the guide and in the examples repository
The goal for this section in the guide will be to present, given a custom exception, a way to assert on the specific fields in that class. For instance, given a custom exception:
package com.example.exception;
public class DetailException extends RuntimeException {
private String detail;
public DetailException(String message, String detail) {
super(message);
this.detail = detail;
}
public String getDetail() {
return detail;
}
}
and a business logic throwing this exception
package com.example.thrower;
import com.example.exception.DetailException;
public class DetailExceptionThrower {
public void throwException() {
throw new DetailException("message", "a detailed exception explanation");
}
}
write an extension to write a test like:
package com.example.thrower;
import org.junit.jupiter.api.Test;
import static org.assertj.extension.DetailExceptionAssertions.assertThatDetailException;
class DetailExceptionThrowerCustomAssertionTest {
private final DetailExceptionThrower underTest = new DetailExceptionThrower();
@Test
void test_customAssertion() {
assertThatDetailException()
.isThrownBy(underTest::throwException)
.withMessage("message")
.withDetail("a detailed exception explanation");
}
}
is it even possible to write an extension like this?
- Ngôn ngữ chính
- CSS
- Star
- 26
- Fork
- 32
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 4
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của assertj/doc
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
-
assertj/doc#167 · 15 bình luận · 3 reaction · 1 người được giao ·
Issue tương tự
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
agilepathway/label-checker#640 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
BasedHardware/omi#15662 · 1 bình luận ·
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100