Questions regarding fluent syntax design for assertions
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 20/100
- Tipo de issue
- Documentación
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- csharp
- Área
- documentation, testing-qa
Línea de trabajo
Comience revisando la documentación sobre assertions y constraints a la que hacen referencia los ejemplos del issue, especialmente Has, Contains y la coincidencia basada en lambdas. Compare la sintaxis documentada de NUnit con los casos de FluentAssertions y, a continuación, aclare la justificación del diseño, las equivalencias compatibles y las limitaciones, de modo que cada ejemplo tenga una respuesta documentada inequívoca.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Coming from XUnit + FluentAssertions, I must say I love the TestCase feature of NUnit.
At the same time I feel that the assertion syntax seems all over the place. The fluent attempt mostly applies to reading the assertion, but definitely not to writing them, because Intellisense gives many false suggestions. And for the number of constraints listed in documentation the possibilities still seem rather limited.
There's nothing preventing me from using FluentAssertions, but I'm trying to understand the philosophy in the current assertion/constraint design in NUnit, especially since a lot of work seems to have gone into it.
First example of clunkiness: why does the Has class have a 'Length' and 'Count' which only work on classes with that exact property name? This leads to tests seemingly perfect by reading the code, but still failing at runtime because a collection was of an unexpected type. It's just confusing while there is a syntax that always works...
[Test]
public void Test_ItemCount()
{
var MyArray = new[] { 1, 2, 3 };
var MyCollection = new List<int> { 1, 2, 3, };
var MyEnumerable = Enumerable.Range(1, 3);
// NUnit assertions
Assert.That(MyArray, Has.Exactly(3).Items);
Assert.That(MyArray, Has.Length.EqualTo(3));
//Assert.That(MyArray, Has.Count.EqualTo(3)); // System.ArgumentException : Property Count was not found on System.Int32[]. (Parameter 'name')
Assert.That(MyCollection, Has.Exactly(3).Items);
Assert.That(MyCollection, Has.Count.EqualTo(3));
//Assert.That(MyCollection, Has.Length.EqualTo(3)); // System.ArgumentException : Property Length was not found on System.Collections.Generic.List`1[System.Int32]. (Parameter 'name')
Assert.That(MyEnumerable, Has.Exactly(3).Items);
//Assert.That(MyEnumerable, Has.Count.EqualTo(3)); // System.ArgumentException : Property Count was not found on System.Linq.Enumerable+RangeIterator. (Parameter 'name')
//Assert.That(MyEnumerable, Has.Length.EqualTo(3)); // System.ArgumentException : Property Length was not found on System.Linq.Enumerable+RangeIterator. (Parameter 'name')
// FluentAssertions
MyArray.Should().HaveCount(3);
MyCollection.Should().HaveCount(3);
MyEnumerable.Should().HaveCount(3);
}
Other examples of clunkiness when it comes to Intellisense:
Assert.That(MyArray, Has.None.Zero); // Pass
Assert.That(MyArray, Is.Not.Zero); // Pass - but probably means something entirely different
// Why do the following even compile?
//Assert.That(MyArray, Has.Exactly(3).Items.All.Exist); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
//Assert.That(MyArray, Has.Exactly(3).Items.All.Not.EqualTo(0)); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
//Assert.That(MyArray, Has.Exactly(3).Items.And.All.All.All.Not.EqualTo(0)); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
Finally, I'm wondering whether it's possible to (1) match using a lambda expression, and (2) drill down into a match to assert its properties. Is there something equivalent in NUnit?
// FluentAssertions
MyArray.Should().ContainSingle(x => x > 2).Which.Should().Be(3);
MyArray.Should().ContainSingle(x => x > 2).Which.Should().Be(3).And.NotBe(4);
var colors = new[] { Color.Red };
colors.Should().ContainSingle(x => x.IsKnownColor).Which.R.Should().Be(255);
// NUnit expected syntax
//Assert.That(MyArray, Contains.Single(x => x > 2) (...) // Syntax error
//Assert.That(MyArray, Has.One.Match(x => x > 2) (...) // Syntax error
//Assert.That(colors, Has.Exactly(1).Items.With.R (...) // Syntax error
- Lenguaje dominante
- Dockerfile
- Estrellas
- 601
- Forks
- 160
- 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 73/100
google/elephant-goldfish-model#586 ·
Los mantenedores suelen responder en 2 días
-
documentation Entwickler
Dificultad 1/5 Menos de una hora Aptitud para principiantes 89/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
memtomem/memtomem-stm#1657 ·
Los mantenedores suelen responder en 1 día
-
Help with the docsAbiertodocumentation good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
lightninglabs/layertree#28 ·