Comments (6)
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.
Related Issues (20)
- Same test takes longer to run if it's running at the end rather than the beginning of a test suite
- .nunit project file with nunit3-console.exe and .net 8.0? HOT 4
- `.ContainKey().WithValue()` and `.Or`/`.And` interact incorrectly HOT 9
- [question] Is there syntactic sugar for asserting the type of exception thrown? HOT 2
- Reason for removing `TestCaseData.Categories`? HOT 4
- add reason to archive https://github.com/nunit/dotnet-new-nunit HOT 1
- NUnit doesn't seem to be able to deal with `PublicSign` HOT 5
- Consider deprecation of TestFixture's "leading args" generic type specification HOT 10
- Increment StreamsComparer by 'Actual bytes read' rather than the buffer size
- Some release note between NUnit 2.6.4 and 3.14.0 should state the breaking change related to Trace and Debug output HOT 4
- Provide a ProgressTraceListener to redirect Trace output to the NUnit Progress output HOT 1
- Value equality on subset of object properties HOT 3
- Difference between net5.0/net6.0 and netframework 4.7.2 in test tear down HOT 5
- Either enable partial TestCaseSource combinatorial with Values, or document this is a limitation of TestCaseSource HOT 1
- Re-add "legacy" Assert methods HOT 7
- Constraint helper classes modification request HOT 3
- State that the scope of a `SetUpFixture` is limited to an assembly HOT 2
- Possibilities to estimate the total test duration before starting the first test? HOT 13
- Provide a way to ignore a failed assertion HOT 14
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.