Comments (7)
The StringAsserts are part of the legacy/classic assertions. Although we don't expect to do anything more with these, what you suggest can be added, as they seem to be just additions, causing no breaking changes or changes to existing assertions.
All the StringAssert methods are implemented in terms of the constraint model, like:
public static void StartsWith(string expected, string actual, string message, params object?[]? args)
{
Assert.That(actual, Does.StartWith(expected), () => ConvertMessageWithArgs(message, args));
}
And this is the way your suggestions should be implemented too.
Suggestion 1 and 3 can easily be added, as they are just simple translations like:
Assert.That(somestring,Is.Not.Null.And.Not.Empty);
PS: Have you considered using the constraint syntax instead?
No 2 and 4 include whitespace, and we currently don't have a constraint for whitespace. (We could probably have that, as it is frequently used in code. ). A solution would be to use the Regex constraint.
We do have an open issue on this, see #3918. Perhaps due time to fix this @stevenaw @manfred-brands ?
The team will probably not do this (except for creating a whitespace constraint or modifier at some time), but we are very open to receive a Pull Request for StringAsserts. That PR also has to contain unit tests for the asserts. It should be easy to add, and placed along with the other string assert tests.
Since this adds functionality it has to go along with the same assertions being documented in the docs repo, under the section for StringAssert.
from nunit.
@OsirisTerje I wouldn't mind adding a Whitespace
constraint and also implement #3918.
I currently work around that issue using Assert.That(NoSpaces(json), Is.EqualTo(NoSpaces(expectedJson))
from nunit.
@manfred-brands Awesome if you implement that!
How should the syntax be ? There are different alternatives, and we should try to be as close as we can to the constraint design.
There might be more than a few scenarios.
Some random thoughts:
Is.EqualTo(sometring).IgnoreWhiteSpace() // Ignores all whitespace in string
or
Is.EqualTo(sometring).WhiteSpace.IgnoreAll // Looks a bit weird to me, but doesnt need multiple variations of WhiteSpace, only modifiers.
so could also be:
Is.EqualTo(sometring).WhiteSpace(IgnoreAll)
Is.EqualTo(somestring).TrimWhiteSpace() // Ignore leading and ending whitespace
or
Is.EqualTo(somestring).WhiteSpace().Trim() or as above include as parameter
Assert.That(sometring,Is.WhiteSpace() // string consist only of whitespace
Assert.That(somestring,Has.WhiteSpace() // string has some whitespace in it
and it should be possible to write
Assert.That(somestring,Is.Not.Null.And.Not.WhiteSpace
from nunit.
@OsirisTerje See #4664
from nunit.
Awesome! Looks very good!
from nunit.
Thanks, I will try and work on this when I have free time, hopefully over the next few months.
from nunit.
@MgSam Hi! Do you have any free time for this coming up ?
from nunit.
Related Issues (20)
- QoL suggestion: fail fast in Assert.Multiple under debugger HOT 11
- Introduce HookExtension to support high level tests HOT 19
- NuGet Package isn't deterministic HOT 2
- Allow fixture-level `Retry` attribute. HOT 4
- F# modules are not initialized during test run HOT 1
- `DefaultFloatingPointTolerance` ignored for `TestCaseData` HOT 3
- Release version 4.2 HOT 8
- `MultipleAssertException` should derive from `AssertionException`, or both should derive from a common e.g. `AssertionExceptionBase` HOT 8
- Document ThrowOnEachFailurUnderDebugger HOT 3
- Assert failure in a Task is not considered for overall Nunit test suite result HOT 5
- Bug report: [Values] doesn't play nice with [CancelAfter]
- Support tuples in inline data HOT 17
- Regression Bug: Multidimensional arrays not handled as of NUnit 3.13.0 HOT 7
- Publicly expose `IgnoreAttribute.Reason` HOT 2
- Update dependencies
- Multiple mains when running nunitlite to test an executable HOT 2
- Bug report: [ValueSource] doesn't play nice with [CancelAfter] HOT 1
- Determine if [TearDown] method is on the stack HOT 2
- NUnit 4.x Android iOS support HOT 4
- Question/Feature Request: Parallel scope for only multiple instances of one parameterized fixture at a time HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nunit.