How do I fake input for form testing?

2019-03-27 23:17发布

问题:

I'm building a test harness for my Delphi 2009 app. Testing the logic is fairly simple. Making sure the forms work properly is proving a bit more complicated. I'd like a way to simulate real user input, to open a form, make it think there's a user typing certain things and clicking in certain places, and make sure it reacts correctly. I'm sure there's a way to do this, I just don't know what it is. Does anyone know how to do it?

回答1:

DUnit has GUITesting.pas whicih extends testing so you can send clicks, keys and text to controls on form, but that is about it.

Last year there where mentions of Zombie GUI testing framework that was used internaly by CodeGear developers, but nothing since Steve left for Falafel.



回答2:

TestComplete is a good choice. Another commercial option for GUI testing is SmarteScript:



回答3:

well for .net there's NUnitForms for GUI testing a win application. don't know any open source for delphi though.

Test Complete can test delphi forms but it's not free.



回答4:

There's 2 parts to this, firstly how do you automate the GUI, and secondly how do I then 'test' whether its working/not working.

Firtsly: To automate the GUI on windows try using AutoIT. Its a free tool for controlling windows interfaces, sending keyboard input events etc. http://www.autoitscript.com/autoit3/

Secondly: Testing is a big field, and I won't try and give you a whirlwind tour. But the mechanics of driving the GUI and testing the results could be handled using AutoIT's built in Basic like language or by using it in conjunction with a language like Ruby and TestUnit (rubys built-in unit testing framework).



回答5:

If there is nothing Deliphi-specic out there and you need a quick solution try some easy to learn scripting solutions like AutoIt. For a bit more sophisticated scripting, you might have a look on Scripted GUI Testing with Ruby.

But be aware, that you should not test too much functionality via the GUI, because such tests are very likely to break. If you end up with too much GUI testing you may need to rethink the design: Decouple logic from the GUI and test the logic directly with some xUnit framework.

Also have a look on a similar question about windows forms test automation.



回答6:

It seems like DUnit has some gui-testing functionality: delphiextreme.com



回答7:

Not exactly an answer to your question, but there is a very good page (IMHO of course) about GUI Architectures by Martin Fowler, featuring the "Humble View" architecture as the last entry, which is geared specifically towards test-driven software development. Worth looking into.

This will of course not help you with the task of testing whether all controls are wired correctly and handle all necessary events, but it should help to minimize the amount of GUI code that does need testing.



回答8:

OpenCTF is good for you.

Quote:

OpenCTF is a test framework add-on for Embarcadero Delphi® which performs automatic checks of all components in Forms (or DataModules).

It provides an easy way to build automatic quality checks for large projects where many components have to pass repeated tests.

Adding OpenCTF tests to a DUnit test suite requires only a few lines of code. Writing your own custom component tests needs only a few seconds.

OpenCTF is based on the DUnit open source test framework and extends it by specialized test classes and helper functions.

Please head here to download.