What do I need to do so that statements no longer block automatic tests?

We run NUnit automated tests on our C # projects using hudson / jenkins on several virtual machines, which in most cases work unattended on any server. Testing involves starting several processes that exchange data, one of which is NUnit itself, and the rest with the unit test.

Sometimes one of the developers checks that it starts the statement ( Debug.Assert() ). Then a window appears with a message about what to do. This usually happens in one of the "external" processes created by unit tests. They will block this process , while other processes will refuse because they cannot communicate. However, due to the nature of the system ,, the following tests will fail if this one process is blocked, expecting someone to close this message box.

I was told that you can change the settings for the .NET program so that the message box does not appear in the application. Ideally, the process would simply write something to stdout or stderr to write Jenkins.

So what do I need to do to disable these dialog dialogs?

+4
source share
2 answers

You need to implement System.Diagnostics.TraceListener, which will not pop up in the Fail dialog box (i.e. you can report an error in the unit test structure) and add this listener instead of the standard one using Listeners.Clear / Add

 public class MyListenerThatDoesNotShowDialogOnFail: System.Diagnostics.TraceListener {.... public override void Fail(string message, string detailMessage) {// do soemthing UnitTest friendly here } } System.Diagnostics.Debug.Listeners.Clear(); System.Diagnostics.Debug.Listeners.Add(new MyListenerThatDoesNotShowDialogOnFail()); 

This code should be in your unit test setup part. Thus, a regular debug build will display confirmation dialogs, but during the execution of unit tests it will do something reasonable for the test (for example, Assert.Fail). Please note that you should consider restoring the original listeners in the testing methods.

+6
source

Do not test the version of the Debug library. You want to know what fails when it is running on the client machine, this will be the release version. Automatically solves your problem with statements.

-1
source

Source: https://habr.com/ru/post/1346110/


All Articles