Improve Documentation To Highlight Reliance on Implementation Details of Assert As Bad
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Dokumentation
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- csharp
- Bereich
- documentation, testing-qa
Rechercherichtung
Beginne mit dem Lesen der Diskussion #168 und des Vorschlags zur Verbesserung der Dokumentation in diesem Issue. Suche anschließend die relevante NUnit-Dokumentation zu Assertions. Als erledigt gilt die Aufgabe, wenn die Verhaltensänderung von Assert dokumentiert, erklärt wird, warum man sich nicht auf Implementierungsdetails verlassen sollte, und die Alternativen Assert.That und Assert.Throws gezeigt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Dockerfile
- Sterne
- 601
- Forks
- 159
- Ø Merge
- 22 Std. 18 Min.
- Gemergte PRs (30 T.)
- 6
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nunit/docs
-
area:adapter type:newpage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workaroundsEvtl. vergeben @SeanKilleen hat das vor 36 Tagen übernommen. Offenarea:framework type:update
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
-
type:newpage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Dependency DashboardOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 15/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
opensafely/documentation#2102 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
agentregistry-dev/website#69 ·
-
15.0
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
-
docs: add SECURITY.md vulnerability reporting policyEvtl. vergeben @AK-Lmn hat das heute übernommen. Offen
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 72/100
flisk-sh/linux2wasm#12 ·
Maintainer antworten meist innerhalb von 1 Tag