When doing Acceptance Testings to the GUI, do tests to the GUI actually show the GUI (in a fraction of a second, I suppose) or are they just mock implementations? I'm talking about frameworks as WindowLicker, White, NUnitForms, etc.
I'm going to assume you mean automated testing. My interpretation of acceptance testing for a GUI involves people actually using the GUI to see if it does what it's supposed to do, in which case you obviously need to show the GUI.
In the test cases I've written for GUI components you usually create a genuine UI without mockups, but don't make it visible. Usually that is sufficient, and mockups of the higher level GUI components can be hard. However a lot of GUI components need to be part of a component tree to function This means that you generally need to run on a machine which has a display, even if you don't use it. There are some functions where GUI components behave differently when they are visible, but I've been able to work round that, with a single exception involving JOGL.
Last time i used it, NunitForms would show the actual Form being tested on screen. You could make it render the actual form off screen if you prefer. I'm not sure about the others you mentioned, i have never used them.
I don't know about the others you mentioned but WindowLicker definitely shows the gui. I don't know if it's possible to run it without doing this, I never tried. It also takes longer than 'a fraction of a second'. You can watch it move the mouse pointer around, click on items, 'typing' text, etc.
Related
I have a moderately sized, highly tangled, messy, big ball-of-mud project that I want to refactor. It is about 50k lines of code and I am the only maintainer. One class is 10k LOC long with line widths of 400 characters. Features are still being added, albeit slowly. I feel good about the refactoring part. Ripping apart code is very comfortable to me. However, getting a set of tests around the application to ensure that I don't break it seems daunting. Huge object graphs and mocking out all the databases will be real buggers. I probably could get away with doing massive refactoring without breaking things horribly. But, prudence dictates some level of tests to ensure at least some level of safety. At the same time, I don't want to spend any more than a minimal amount of time getting a set of "behavior lock-down" tests around the code. I fully intend to add a full set of unit tests once I get things a bit decoupled. A rewrite is a non-starter.
Does anyone have any pointers or techniques? Has anyone done this sort of thing before?
Mindset
Generally it can be tough going trying to write automated tests (even high level ones) for applications that were not build with testability in mind.
The best thing is going to be make sure you are disciplined in writing tests as you refactor (which it sounds like you are intending to be). This will slowly turn that ball of code, into an elegant dancing unicorn of well encapsulated testable classes.
Suggestions
Start with creating some manual high level tests (e.g. user goes to page one, clicks on the red button, then a textbox appears..) to have a starting point. Depending on the technology the app is built in there are a few frameworks out there that can help automate these high level (often UI driven) tests:
For web apps Selenium is a great choice, for WPF apps you can use the UI Automation framework, for other application, while its a bit rudimentary, AutoIt can be a life saver.
Here how I do it in c++ (and c-).
Create a directory to house the tests, cd to this directory
Create a directory to house mock objects, say mock-objs.
Create a makefile to compile all object files of interest.
Add necessary include directories or mock .h files to make all object file compile.
Congratulate yourself you are 90% done.
Add a test harness of your choice (e.g. cppunit, atf-tests, google test ..).
Add a null test case - just start, log and declare success.
Add necessary libraries and/or mock .c/.cpp files until link is successful and the very first test passes. Note: all functions in these .c/.cpp mock files should contain only a primitive to fail the test when called.
Congratulate yourself you are 99% done.
Add a primitive event scheduler: say just list of callbacks - so you can post request and receive response from event callback.
Add a primitive timer: say timer wheel or even timer list if you need just a few timers.
Write advance-time function: (a) process all queued events (b)increment current time to the next tick, (c)expire all timers waiting for this tick, (d)process all queued events over and over again until no events left, (e) if end the time advance is not reached go to step(b).
Congratulate yourself: now you can add tests with relative ease: add a test case, modify mock functions as required, repeat.
We are looking to write automated tests using coded ui test framework. We are looking to test the ui components in isolation without launching the application in a separate process.
For example if we have a pop-up dialog in the application to capture data from user, we would like to launch only the specific dialog and validate different use cases rather than running the whole application.
We tried to test by launching the dialog as part of the test initialize() but it is not able to find the controls... but the same test works fine if I launch the dialog separately.
Have anyone tried this or have advise to get this working ?
Coded UI Framework is a very powerfull framework yet has lots (and I mean LOTS) of problems.
I wouldn't recommend it to do what you are trying to accomplish.
Besides, testing "components in isolation" is unit testing, and from my experience this is not a best practice for Coded UI Test at all.
Coded UI test will help you in testing cross-application processes from end to end, closest to the user as it gets since its simulating the users inputs though keystrokes and mouse clicks.
Also, as UI tends to change quite a lot during development, and Coded UI relies on that, I suggest you use it mainly for regression testing for windows you know that are not going to change anytime soon.
This way you'll keep you maintainance low and productivity high.
Hope this helps.
Coded UI is intended for checking the functionality of applications (and also of web pages). Coded UI is not for testing fragments of UI separate from their application. However, it would be possible to create a test harness application that contained one or more UI components allowing them to be tested in isolation from the real application.
A test harness could easily have a window for each component being tested. The window would include the component being tested plus a some other simple controls. These simple controls could expose internal values of the component being tested and also be used to pass values into the component.
I think what your attempting to do is viable, however ONLY for your own custom controls. I think you should tackle this in this order.
A second instance of VS to capture what it actually sees about your control when your test spawns your control.
Update your search criteria, e.g. process name, window title
Potentially add properties to your TestInitialize spawner so it creates your control with useful ID's, names, or titles. (not sure which tech stack your control is in)
Run tests again
So we have a bunch of different processes setup in code right now. We have a framework setup around this with a couple of classes that control when these pieces of code are kicked off, where they log to, which other process they depend on, etc.
The way we currently work this is that all of these processes inherit a base one that contains parameters, a Validate() method, and a Start() method.
I'd like to re-do this. Right now the code is very difficult to deal with. I think each process in it of itself is setup fine, but I would like to know if there are any frameworks that anyone has used to setup what is basically just a scheduler that kicks off certain processes at different times throughout the day.
Each process should have the ability to depend on another one, have its own set of parameters, a kick off time, a frequency (Daily, Ad-hoc, etc.), and the ability to log its messages and any exceptions to the UI. The reason we want to keep interdependence is because a process shouldn't run if one it depends on fails.
Anyone know of a good framework to set something like this up?
Thanks.
You might want to have a look at Quarz.NET. Looking at the project page, it seem to be reasonably active. Disclaimer: personally never used it.
My question is how programmers create, code, and organize subforms in general. By subforms, I mean those groups of controls that make up one UI experience. I'm looking for hints to help me better organize my form codes and to speed up the process of creating such forms. I swear to God, it takes way too long.
I've identified three broad groups of subform elements:
-Subforms have commands to do something.
-Subforms have data elements to carry out those commands.
-Subforms have states used to track things that aren't data.
The approach I use is to focus on what it takes to perform the commands which will determine which data elements are needed and how they should be validated.
Also, do programmers use check lists when creating forms?
p.s. I program as a hobby.
This is incredibly fuzzy. There is however a red flag though, you seem to be talking about UI as a starting point instead of the end result. That's a classic trap in winforms, the designer is rather good and makes it way too easy to endlessly tinker with form layouts. You forever keep adding and removing controls and event handlers as your ideas about how the program is supposed to work evolve.
This is backward and indeed a huge time sink. Effective design demands that you grab a piece of paper and focus on the structure of the program instead. The starting point is the model, the M in the MVC pattern. As you flesh out how the model should behave, it becomes obvious what kind of UI elements are necessary. And what commands should be available to the user.
The V emerges. Instead of jumping into the designer, sketch out what the view should look like. On paper. Make a rough draft of an organized way to present the data. And what operations are available to the user to alter them. Which selects the type of controls and the menus and buttons you'll need. Once that congeals, you can very quickly design the form and add the C. The event handlers that tie the UI to the model.
There's a very interesting tool available from Microsoft that helps you to avoid falling into this trap. I love the idea of it, it intentionally makes the UI design step imperfect. So you don't spend all that time pushing pixels around instead of focusing on the design of your program. It draws UI designs in a paper-and-pencil fashion, there are no straight lines. Incredibly effective not just for the programmer, also a "keep the customer focused and involved" fashion. So that the customer doesn't fall in the same trap either, nagging about a control being off by one pixel. It is called SketchFlow, link is here. It is otherwise the exact same analogue of paper and pencil, but with a 'runs on my machine' flourish.
Try CAB I'm not sure you should use it, but the pattern will help you understand how to write your gui layer in a good way.
I was thinking of centralizing this functionality by having a single method that gets passed an AppState argument and it deals with changing the properties of all GUI elements based on this argument. Every time the app changes its state (ready, busy, downloading so partially busy, etc), this function is called with the appropriate state (or perhaps it's a bit field or something) and it does its magic.
If I scatter changing the state of GUI elements all over the place, then it becomes very easy to forget that when the app is in some state, this other widget over there needs to be disabled too, etc.
Any other ways to deal with this sort of thing?
Emrah,
Your idea is good. You need to limit the state structure and this is the only way to ensure reliable UI. On the other hand do not follow the "one function" idea to strictly. Rather continuously follow its direction, by creating a function and then do progressively refactoring all attributes to a single "setter" function. You need to remember about a few things on your way:
Use only one-way communication. Do not read the state from controls since this is the source of all evil. First limit the number of property reads and then the number of property writes.
You need to incorporate some caching methodology. Ensure that caching does not inject property reading into main code.
Leave dialog boxes alone, just ensure that all dialog box communication is done during opening and closing and not in between (as much as you can).
Implement wrappers on most commonly used controls to ensure strict communication framework. Do not create any global control framework.
Do not use this ideas unless your UI is really complex. In such case using regular WinForms or JavaScript events will lead you to much smaller code.
The less code the better. Do not refactor unless you loose lines.
Good luck!
Yes, this is the most time consuming part of the GUI work, to make a user friendly application. Disable this, enable that, hide this, show that. To make sure all controls has right states when inserting/updateing/deleteing/selecting/deselecting things.
I think thats where you tell a good programmer from a bad programmer. A bad programmer has an active "Save"-button when there is nothing changed to save, a good programmer enables the "save"-button only when there are things to save (just one example of many).
I like the idea of a UIControlstate-handler for this purpose.
Me.UIControlStates=UIControlstates.EditMode or something like that.
If having such object it could raise events when the state changes and there we put the code.
Sub UIControlStates_StateChanged(sender as object, e as UIControlStateArgs)
if e.Oldstate=UIControlStates.Edit and e.NewState=UIControlStates.Normal then
rem Edit was aborted, reset fields
ResetFields()
end if
select case e.NewState
case UIControlStates.Edit
Rem enalbe/disable/hide/show, whatever
Case UIControlStates.Normal
Rem enalbe/disable/hide/show, whatever
Case UIControlStates.Busy
Rem enalbe/disable/hide/show, whatever
Case Else
Rem enalbe/disable/hide/show, whatever
end select
end sub
#Stefan:
I think we are thinking along the same lines, i.e. a single piece of code that gets to modify all the widget states and everyone else has to call into it to make such changes. Except, I was picturing a direct method call while you are picturing raising/capturing events. Is there an advantage to using events vs just a simple method call?