Improve Documentation To Highlight Reliance on Implementation Details of Assert As Bad
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- csharp
- Área
- documentation, testing-qa
Línea de trabajo
Comienza leyendo la discusión #168 y la sugerencia de mejora de la documentación en este issue; después, localiza la documentación relevante de NUnit sobre las aserciones. Se considera terminado cuando se documente el cambio de comportamiento de Assert, se explique por qué no se recomienda depender de los detalles de implementación y se muestren las alternativas Assert.That y Assert.Throws.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Dockerfile
- Estrellas
- 601
- Forks
- 159
- Merge medio
- 22 h 18 min
- PR fusionados (30 d)
- 6
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nunit/docs
-
Document the adapter's agent output settings (AgentMode, ShowStdout, ShowStderr, StackTrace)Abiertoarea:adapter type:newpage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workaroundsPosiblemente ocupada @SeanKilleen la tomó hace 36 días. Abiertoarea:framework type:update
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
-
type:newpage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dependency DashboardAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 15/100
-
Move console/engine wiki to docsAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Todos los issues de nunit/docs
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
opensafely/documentation#2102 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
agentregistry-dev/website#69 ·
-
15.0
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
-
docs: add SECURITY.md vulnerability reporting policyPosiblemente ocupada @AK-Lmn la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
flisk-sh/linux2wasm#12 ·
Los mantenedores suelen responder en 1 día