How to mock an external server for a client unit test

315 views
Skip to first unread message

javier.g...@gmail.com

unread,
Jul 19, 2017, 11:04:54 AM7/19/17
to finatra-users
Hi,
I am trying to write some unit tests for a client application using an external service.

I just want to test my client functionality, error handling, etc.

Reading the Finatra test documentation and provided examples, it seems they are focused on testing a server, or a client for a server running locally.

The problem is that in my case the server is external and I do not have access to it. I want to avoid making an actual call to the server from my unit test environment.

Thanks!

Jordan Parker

unread,
Jul 19, 2017, 1:39:44 PM7/19/17
to javier.g...@gmail.com, finatra-users
Hi Javier -

If the client talking to your service is provided by a module, take a look at override modules. You can use that to provide a fake client for testing purposes.

Hope that helps!
-J


--
You received this message because you are subscribed to the Google Groups "finatra-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to finatra-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

javier.g...@gmail.com

unread,
Jul 19, 2017, 1:52:24 PM7/19/17
to finatra-users
Hi Jordan, thank you for your response.
In fact it is actually the other way around. The service is external, and I just want to test my client.
I need to stub the server responses.

Christopher Coco

unread,
Jul 19, 2017, 2:09:53 PM7/19/17
to javier.g...@gmail.com, finatra-users
Hi Javier,

Without knowing your exact specifics, you can always create a simple test server, start it in a FeatureTest, configure your client to point to it and write/run your tests. Finatra is ostensibly focused on writing servers but you should be able to easily test a client with a real (dummy) server in a FeatureTest. 

If you just want to mock server responses to your client, then simple unit tests would probably suffice and you don't need anything from the framework.

Thanks,
-c

javier.g...@gmail.com

unread,
Jul 20, 2017, 5:20:07 AM7/20/17
to finatra-users, javier.g...@gmail.com
Thanks much Christopher,
You are right, the best way to go would be to create a test server, and maybe mock different responses with Finatra.
/Javier
Reply all
Reply to author
Forward
0 new messages