Professional Development – 2024 – Week 39

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

Testing in .NET is About to Change (via Nick Chapsas)

  • XUnit is solid and has some good defaults. If you need more control, there’s a new library called TUnit. Warning: As of this writing, the library isn’t even at a 1.0 release.
  • Every assertion must be awaited.
  • The library generates code that invokes the test, which you can inspect. There’s also the benefit of not needing reflection to find the tests in an assembly to run. Because of this, the tests don’t show in the testing console in the IDE; you have to run dotnet test from the console or configure your IDE to use the new testing platform (as opposed to VSTest).
  • There’s a way to create before-test hooks (which you can also do in other unit testing frameworks), but you get access to the test context, which has information about timings, results, etc. You can also have hooks for before running any test in the class, any test in the assembly, the test session, the test discovery.
  • You can also designate that certain test methods, depend on other tests. Warning: Don’t use this in unit tests, but it can be useful with integration/acceptance tests.
  • There’s the ability to retry tests (for integration/acceptance tests).
  • The fluent syntax is a bit clunky, but may improve before release.

LINQ’s INSANE Improvements in .NET 9 (via Nick Chapsas)

  • Many of the common LINQ methods (e.g., All, Count) have been optimized for performance and memory usage.
  • The magic involves Span and Unsafe. To me it sounds like the .NET team is making it easy to take advantage of Spans without the developer having to do anything extra. An upgrade to .NET 9 will bring performance improvements without rewriting any of your existing code.
  • There are more context aware uses of iterators — for example skip/take, select/where that traditionally use two iterators now use one.

Stop Using Booleans in Your Code! | Code Cop #022 (via Nick Chapsas)

  • The only reason you should avoid using a Boolean argument is if the logic for “true” and logic for “false” do very different things. In this case, split the method into two methods.