What are good approaches to test dates?
morde last edited by user
Currently my team is writing some Selenium-based web tests using Java for our application. One major stumbling block has been centred around testing dates. To me, it seems too awkward to test dates in the UI using Selenium. Formatting, setting and reading dates is difficult with an automated tool.
For example, some fields have a From Date and To Date that are set by using a calendar interface where the user selects the day month and year. Text is read-only, so can't be set directly. Automating such actions is not easy using Selenium (or most UI automation tools, I'd guess).
Apparently, it's also a lot of work for manual testers to execute the same tests.
I'm wondering if dates are better tested at the unit level, by developers using unit or integration tests. What are some good strategies?
I have found value from testing date time issues at all layers of an application. Which layer is determined by what I am trying to test. For instance:
Testing Functional Logic:
Assuming for a second that you don't have core logic built into your UI code (Model View Separation or something similar). It is often easier to test the core logic layer by mocking up the UI and dealing with core logic date testing as strict API functional testing. How much testing you do is basically limited by time and resources to automate then.
Using this methodology you can select a test set based on (some examples):
- Brute Force: Test all valid date range inputs. This is feasible when your date handling logic is fast, or the valid list of date is small (like years as input, excluding months and days).
- 80% User Scenario: Use data analysis of usage patterns to determine a subset of tests that will keep 80% of your user base happy. This is useful if you are selecting something similar to birthday entry, when your target demographic is tweens. Yes some octogenarians may use the site but your core audience is kept happy.
- Edge Cases: Leap years, Date Addition (does Jan 30+1 month == Feb 28)?, Time Zone? ect ect ect
Because this list is long and you get better coverage the more per formant the code is, it gets very hard to automate this Functional Logic testing through a UI automation framework.
Testing UI Functionaliy:
I believe in using a UI framework to test basic functionality of the UI (does the UI give information to the backend correctly). These slower, possibly more error prone (sometimes complicated tests) to a minimum also increases your test maintainability (since frequent UI changes don't break you).
Testing UI Date Time Usability
This is something I have never fully been able to automate. This is basically the realm of the manual tester, large beta groups, user research studies, or common sense. Does the date picker make you scroll through every year starting at 1900? That wont get caught until somebody actually has to use it.