How to unit test my Google OpenID consumer app?

723 Views Asked by At

My web app is a Google OpenID consumer (with Attribute Exchange and OAuth Extension) and I need to write some unit test for it [edit: to test the unit that is responsible to interact with google].

The problem is that default OpenID login procedure needs user interaction (entering user/pass) which is not possible in unit test.

Do you have any idea how can I solve this problem and unit test my OpenID consumer app?

(I prefer not to run my own OpenID provider.)

2

There are 2 best solutions below

1
On BEST ANSWER

You need to use a remote controlled browser for this. Selenium was made for this use case.

(indeed they are called functional tests then).

Search on Google for the best way to integrate selenium tests into your web framework.

1
On

If I understand you want to test your all application and not just "unit test" it. The actual test framework depends on the technology your application is using. For example there are many UI and web automation tools that can do what you want.
You should also unit test your core functionality or at least write several integration tests that work against an actual Openid provider but instead of running the entire application just test the functionality of the class (if you're using language that has classes) to make sure it can get the b. I would also write a couple of unit tests that call a fake provider to test how your code behaves in case of error, connection problems and plain vanilla responses.