How to unit test applications that require authentication

I’m currently working on building an automation library for a piece of software the business uses. It requires authentication to access and I’m wondering how to approach unit testing UI interactions with software like this?

For example, one part of the process requires you to authenticate, then select a specific dealer from a popup modal, then select a record on the dealer dashboard and then process it. Those are sequential steps that have to be taken to land on a record. So how would I approach testing workflows that work with those records?

So far I’ve just been invoking other workflows as part of the setup for a given unit test, i.e. the dealer selection test case invokes the sign in workflow as part of the test setup.

I’m not sure if that’s the correct approach, though I can’t think of another way to approach it. Searching around online didn’t return anything useful so I’m hoping someone on here can help me out!

Its a good question.

The approach I implemented in my company was to make sure all unit tests can run fully independently. This means that the any actions such as logging onto an application occur before the unit test and after its completed the environment is cleaned up and the application is closed.

This is the only way to correctly do it as otherwise you cannot support automated testing. In automated testing each test case or unit test becomes a distinct job. Since you cannot guarantee each test will execute in order or another job won’t run between unit tests they must be self contained.

I follow the BDD test template.
In the Given I used to do the login actions, in the Then section I would do close and cleanup.
This wasn’t ideal as it created alot of repetition.
I now use Execution templates to help reduce this. The execution templates can help handle the authentication and cleanup.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.