Improve Documentation To Highlight Reliance on Implementation Details of Assert As Bad
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Documentação
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- csharp
- Domínio
- documentation, testing-qa
Direção de pesquisa
Comece lendo a discussão #168 e a sugestão de melhoria da documentação nesta issue; em seguida, localize a documentação relevante do NUnit sobre asserções. O trabalho estará concluído quando a mudança de comportamento de Assert estiver documentada, quando for explicado por que não é recomendável depender de detalhes de implementação e quando as alternativas Assert.That e Assert.Throws forem mostradas.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Dockerfile
- Estrelas
- 601
- Forks
- 159
- Merge médio
- 22h 18min
- PRs com merge (30d)
- 6
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de nunit/docs
-
area:adapter type:newpage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workaroundsTalvez já em andamento @SeanKilleen assumiu há 36 dias. Abertaarea:framework type:update
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
-
type:newpage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dependency DashboardAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 15/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
audacity/audacity.github.io#118 ·
-
bug improve content
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
opensafely/documentation#2102 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
agentregistry-dev/website#69 ·
-
15.0
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
-
docs: add SECURITY.md vulnerability reporting policyTalvez já em andamento @AK-Lmn assumiu hoje. Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 72/100
flisk-sh/linux2wasm#12 ·
Mantenedores costumam responder em até 1 dia