r/MSAccess • u/brosama1420 • 14d ago
[UNSOLVED] Testing Forms controls and UI/UX
Hey everyone
Good morning
I use Rubber duck VBA Add In
So I test all logical code easily (automatic testing by code)
However I am struggling to test UI stuff without changing the actual program status
I don’t want my test to create changes in the production or design environments
Can anyone help me in this matter?
2
u/CanProfessional766 8d ago
Honestly I’d keep UI testing completely separate from production. Make a copy of the Access database with some test data and do all your form/control testing there. You can click around and test events without worrying about messing up the real data. Rubberduck is great for testing VBA logic but for UI stuff a separate test database is probably the simplest and safest approach.
1
u/George_Hepworth 4 13d ago
What, exactly, would that help look like? What "UI stuff" needs testing? What changes are you concerned about the tests causing? How can you even test without something to test on?
I'll bet someone has relevant experience, but the more clear the situation, the more likely you'll get useful responses.
1
u/brosama1420 13d ago
I want to know how to write a code that test them in the first place
They do exist but I want to do smt close to mocks and stubs because I don’t want the test to do stuff to my actual tables and forms this might slow the testing process as it grows and making changes to the controls forms or even tables in the future could affect the program
I want to know how to write testing code in VBA that is Isolated in ms access ofc
I could think of ways to make the code open the form, click btns navigate the form or even write stuff in text box or combo box but how to make the test Isolated from my db and ui this one seems vague to me
1
u/brosama1420 13d ago
Also regarding testing UI i have only learned about it through u tube I have not test any UI for real before
1
u/George_Hepworth 4 13d ago
Okay, by testing forms, you mean:
- Code to open a form.
- Code to click buttons on the form.
- Code to navigate the form (what navigation means remains to be determined)
- Code to insert values into text boxes
- Code to make selections in combo boxes
The criteria for success depends on what behavior you want to see, but it might be something like:
"When clicking a menu option on the main menu form, the correct form opens and moves focus to the [correct] record."
You can answer such questions "yes" or "no". Passed the test or not.
The same is true for all of the things you want to test. Try to write the criteria so that your answer is always one of two options: Pass or Fail. Did the desired behavior happen or not?
All very doable.
The concern is that doing this testing may involve making changes to data in the test database. A very real concern, but one with an easy to implement solution.
The obvious solution is to create a test version of the database. Copy it and rename it, "MyDatabaseName_Test.accdb" where MyDatabaseName is the actual name of yours.
Assuming that your Access database is properly split, you'll have both an
MyDatabaseNameFE_Test.accdb and
MyDatabaseNameBE_Test.accdbLink MyDatabaseNameFE_Test to the tables in MyDatabaseNameBE_Test
The data in MyDatabaseNameBE_Test.accdb should be an exact copy of the live production data, but because it's a test version, that data is disposable after testing. If it does get changed during testing and you need to repeat tests, throw it away and get a new copy from the original, production database. Keep doing that until all tests pass.
Once you've tested every feature and passed them, you are ready to replace the original FE with the tested version and relink it to the live production data.
Are there other concerns?
1
u/brosama1420 13d ago
How about the events? For me when I want to test the buttons ofc I need their events at least the ones I wrote codes into
Using recordsets or vba to directly interact could skip the controls or form events how can I solve this issue?
1
u/George_Hepworth 4 13d ago
Write additional tests for each of those paths.
State what needs to happen.
State the conditions that exist when the test is run.
State how you'll know the test succeeded.For each path, e.g. using recordsets, state how the test runs, such as "when the user does X, the VBA procedure Y runs. The recordset in Y does Z. Success is indicated by A outcome."
In other words, you have one test for each potential action a user can take. I don't know what those actions are. All I can do is suggest the patterns you need to follow.
I find this blog article to be extremely helpful in thinking about documentation driven development, where the tests are based on the documented behavior expected.
1
u/fanpages 53 13d ago
...Can anyone help me in this matter?
[ https://rubberduckvba.ca/contact-us ] and/or [ https://github.com/retailcoder ].
(As Mathieu Guindon [u/Rubberduck-VBA] is no longer a Redditor)
1
u/fanpages 53 12d ago
u/brosama1420 - FYI (if you have not seen this reply in your r/VBA thread):
[ https://www.reddit.com/r/vba/comments/1vspuib/testing_forms_controls_and_uiux/p4qu2qf/ ]
👋 still lurking!
Rubberduck unit tests are just that: unit tests - it's a kind of test where you're specifically not testing the UI directly but the model that underpins it, usually for correctness rather than UX.
There are probably ways to do what you want, but how I'd do it would be to explicitly define what "UX" means, encode that behavior into the model, bind the form to the model, and test the model. The Model-View-Presenter pattern works well for this with MSForms. For example if the visibility of a control depends on a condition, move that condition out of the UI and test the condition instead of the UI.
Then in theory you can have a test that instantiates the form class without displaying it, wires up the model and you can assert that control properties are as expected - but the minute an automated unit test brings up a UI, it's still a valid test, just not a unit test anymore; in other words Rubberduck may or may not be used for that purpose, YMMV.
As for the status of the project, the last pre-release is the latest version available; Rubberduck is a very heavy code base with a model that was taken to its limits, and of course there are a ton of issues but overall the latest pre-release build is the most stable and full-featured Rubberduck build. I need to focus on the model Rubberduck needed all along, and that's the Rubberduck Core language platform project, which is very much alive - VIVAT CUCUMIS!
1
1
u/brosama1420 12d ago
Btw in rubberduck I saw smt called stub any idea how to use this and where/when to use it?
1
•
u/AutoModerator 14d ago
IF YOU GET A SOLUTION, PLEASE REPLY TO THE COMMENT CONTAINING THE SOLUTION WITH 'SOLUTION VERIFIED'
Please be sure that your post includes all relevant information needed in order to understand your problem and what you’re trying to accomplish.
Please include sample code, data, and/or screen shots as appropriate. To adjust your post, please click Edit.
Once your problem is solved, reply to the answer or answers with the text “Solution Verified” in your text to close the thread and to award the person or persons who helped you with a point. Note that it must be a direct reply to the post or posts that contained the solution. (See Rule 3 for more information.)
Please review all the rules and adjust your post accordingly, if necessary. (The rules are on the right in the browser app. In the mobile app, click “More” under the forum description at the top.) Note that each rule has a dropdown to the right of it that gives you more complete information about that rule.
Full set of rules can be found here, as well as in the user interface.
Below is a copy of the original post, in case the post gets deleted or removed.
User: brosama1420
Testing Forms controls and UI/UX
Hey everyone
Good morning
I use Rubber duck VBA Add In
So I test all logical code easily (automatic testing by code)
However I am struggling to test UI stuff without changing the actual program status
I don’t want my test to create changes in the production or design environments
Can anyone help me in this matter?
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.