The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,466 other followers

Archive for January 26th, 2021

Run your unit tests in parallel with NUnit

Posted by jpluimers on 2021/01/26

TL;DR

The examples in this post are specific for NUnit but, you can apply this pattern for safely running unit tests in parallel to any unit test framework that supports parallel execution.

To safely run tests in parallel, do the following:

  1. Mark your test fixtures with the Parallelizable attribute and set the parallel scope to ParallelScope.All.
  2. Create a private class called TestScope and implement IDisposable.
  3. Put all startup and clean-up logic inside the TestScope constructor and .Dispose() method respectively.
  4. Wrap your test code in a using (var scope = new TestScope) { ... } block

From [WayBack] Run your unit tests in parallel with NUnit, which also covers:

  • Background (on why you might want this)
  • How to safely run tests in parallel
  • Maximizing parallel execution with Visual Studio
  • Maximizing parallel execution with Azure DevOps

Via: [WayBack] Sander Aernouts on Twitter: “Run unit tests in parallel with NUnit without having one test interfere with another test. https://t.co/FC0fNocGov”

–jeroen

Posted in .NET, Development, Software Development | Leave a Comment »

datetime – Determine Whether Two Date Ranges Overlap – Stack Overflow

Posted by jpluimers on 2021/01/26

[WayBack] datetime – Determine Whether Two Date Ranges Overlap – Stack Overflow answer by Charles Bretana with input from Baodad and tomosius.

TL;DR (proof is in the post)

(StartA <= EndB) and (EndA >= StartB)

Alternative (also from the post):

DateRangesOverlap = max(StartA,StartB) < min(EndA,EndB)

It gets complicated when the date boundaries for A and B can be out of order.

The post also covers that.

Related:

–jeroen

Posted in Development, Software Development | Leave a Comment »

Delphi debugging tip: keep an eye on a object field of an object that will go out of scope eventually

Posted by jpluimers on 2021/01/26

Every once in a while you want to have a Delphi Watch of a field inside an object (say an object of type TContext), except that the field has no value yet, but eventually will point to another object (say an object of type TUser).

However, the original object will go out of scope, so you need to employ a few tricks.

First of all, you get the address of that field:

@(Context().FCurrentUser) = $7EF6F624

Then you watch the content of that field:

TUser(PPointer($7EF6F624)^),r = nil

To get to this trick, you have to remember:

  1. The contents of address $7EF6F624 is pointer (at first nil) to a TUser.
  2. You get to the contents of the address $7EF6F624 by using PPointer($7EF6F624)^.
  3. Then you cast it to the object you want with the TUser(...) cast.

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

 
%d bloggers like this: