0

I am working on the C# Windows Forms application.

All business logic is on the DataBase side (PLSQL). On C# side is just a front-end (listboxes, checkboxes, and buttons to get data from DB). I wanted to write some Unit Tests for it, but cannot use Windows Forms in NUnit3 (VS doesnt see a library, cannot create an object of ComboBox etc.)

My question is - is there any possibility to test UI items by NUnit? And is there any sense of testing it while business logic is on the DB side?

1

2 Answers 2

0

To be clear, tools that test through the UI, driving clicks, entries, etc., are not unit tests. They are simply a way to automate the kind of application testing a good tester would do, minus the creative insight of the human tester.

A well-designed GUI, including one written for Windows forms, can benefit from unit tests, but it doesn't usually need as many as the back end requires. For example, you don't need to test that a TextBox displays the text you put into it - the code for TextBox isn't your code. You may want to test that the correct text is actually given to the TextBox and that the location and size of the TextBox are set correctly - at least that it's visible on the screen.

It's your judgement call as to how much of that type of testing is needed. If you want to write such tests, NUnit is a good tool for doing so - as are most test frameworks at the same level. If you are new to NUnit and/or programmatic unit testing, you should be aware that most people consider this sort of GUI testing as somewhat more advanced than backend testing. (I used to give classes in Windows GUI testing and I aimed them at folks who already knew NUnit an had been doing unit testing with it for a few years.)

My advice would be to find places in the GUI where you have seen or anticipate errors. For example, you may have a checkbox that controls whether other controls are active or not. This sort of UI logic is exactly the thing for which unit tests of the GUI are valuable.

General advice...

  • Don't try to unit test appearance - just look at it!

  • Use mocks to replace any backend database or server-side code.

  • Use an architecture that allows separate testing of GUI logic - I like MVP for Windows Forms and (obviously) MVVM for WPF.

  • Test origination and handling of events separately, not as one thing. That's particularly important with events that originate in the SWF controls.

If you do this and run into specific issues, just give us another question.

Sign up to request clarification or add additional context in comments.

Comments

-1

If your are creating your project from visual studio it's gives option for unit testing project with the main project creation, https://learn.microsoft.com/en-us/visualstudio/test/create-a-unit-test-project?view=vs-2019 .Also may be this help you https://social.msdn.microsoft.com/Forums/windows/en-US/5239f415-3156-4871-96de-751616865ef2/how-to-do-unit-testing-for-windows-form-application?forum=vsunittest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.