Improve Documentation To Highlight Reliance on Implementation Details of Assert As Bad
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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ệ
- csharp
- Lĩnh vực
- documentation, testing-qa
Hướng nghiên cứu
Bắt đầu bằng cách đọc cuộc thảo luận #168 và đề xuất cải thiện tài liệu trong issue này, sau đó tìm tài liệu NUnit liên quan về assertion. Công việc được xem là hoàn thành khi đã tài liệu hóa thay đổi về hành vi của Assert, giải thích lý do không nên dựa vào các chi tiết triển khai và trình bày các lựa chọn thay thế Assert.That và Assert.Throws.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This is a continuation of this discussion: #168 I completely agree with @CharliePoole on this, but I would suggest that the documentation be improved to highlight the situation.
-- Begin Documentation Improvement Suggestion --
Behavior of Asserts
[Test]
public void TestAssertCatch()
{
try
{
Assert.That(true, Is.False);
}
catch
{
}
}
When looking at this example you may expect NUnit to Assert that true != false. However in versions of NUnit Prior to 3.6.0.0 this test would pass due to an implementation detail of Assert. In newer versions of NUnit this will Assert (and fail the test) as a design decision of the NUnit.org Team.
In cases where this is used, it was probably used in scenarios where better APIs could be leveraged.
Consider the following test which is trying to Assert that an Exception is thrown/not thrown:
public void TestException()
{
try
{
GuessTheNumber(42);
// This code only executes if no exception has occurred
Assert.Fail("An expected exception did not occur");
}
catch(Exception ex)
{
Assert.That(ex.Message, Is.EqualTo("The Answer"), "An expected exception did not occur");
}
}
public static void GuessTheNumber(int number)
{
if(number == 42)
{
throw new Exception("The Answer");
}
}
Instead this should be rewritten to use either Assert.That or Assert.Throws like so:
[Test]
public void TestExceptionAssertThat()
{
Assert.That(() => GuessTheNumber(42), Throws.InstanceOf<Exception>().With.Property("Message").EqualTo("The Answer"), "An expected exception did not occur");
}
Or Assert.Throws Style
[Test]
public void TestExceptionAssertThrows()
{
Exception ex = Assert.Throws<Exception>(() => GuessTheNumber(42), "An expected exception did not occur");
Assert.That(ex.Message, Is.EqualTo("The Answer"), "An expected exception did not occur");
}
-- End Documentation Improvement --
As Charlie mentioned:
I have asked the submitter of the issue to give a motivating example that would help us meet the need
It would be nice to hear what other scenarios end users are encountering that cause them to need to capture the exception of the Assert. The above example is just what we found in our code base during our 2.6.4->3.11.0 Convert.
Thank you for this tool; it is invaluable to us.
- Ngôn ngữ chính
- Dockerfile
- Star
- 601
- Fork
- 159
- Merge trung bình
- 22 giờ 18 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 nunit/docs
-
Document the adapter's agent output settings (AgentMode, ShowStdout, ShowStderr, StackTrace)Đang mởarea:adapter type:newpage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workaroundsCó thể đã có người làm @SeanKilleen đã nhận 36 ngày trước. Đang mởarea:framework type:update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
-
type:newpage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Dependency DashboardĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 15/100
-
Move console/engine wiki to docsĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensafely/documentation#2102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
agentregistry-dev/website#69 ·
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày