nunit interactive tests running on .net core 2.1

21 Views Asked by At

I have a special requirement... While testing a GUI application, it sometimes pops up various unexpected windows :( In order to keep everybody happy I want to implement a kind of interactive testing framework.

I am already wrapping each GUI operation and assertion in a retry mechanism, hence everything is retried several times before giving up.

I can add a fallback to this mechanism to popup some message box or wait for a keystroke in order to continue. This will give the tester/developer a chance to rectify the misbehaving application and continue the test instead of relaunching it.

I am constrained to use .NET Core 2.1 --

  1. Is there any way to popup a simple yes/no message box? As far as I remember from Win32 days it is just a calling one function https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
  2. Is it possible to somehow get around the annoying console capturing behaviour of NUnit? I was able to make Console.Write work immediately but Console.ReadLine is just getting stuck :( https://github.com/nunit/nunit/issues/1139

TIA, Adrian

1

There are 1 best solutions below

0
Adrian Herscu On

After more digging...

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

Console.WriteLine("> "
  + MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 4));

will display a yes/no popup :)