I am developping a Swing application that needs to communicate with a distant HTTP server. That application can be potentially used behind proxies.
I must then :
– detect automatically network proxy (potentially several on the same network)
– let the user manually enter a proxy configuration.
I want to write an integration test to validate thoses aspects, without having to install proxies on every CI machines and every developper machine.
How I see things :
- integration test (with junit) start an “embedded” proxy (@BeforeClass) and a somewhat dummy http server
- my tests (@Test)
- test that this proxy can be detected automatically and open a connection to my dummy http server and successfully retrieve datas from it
- manually set the proxy and perform the same test as above
I have heard about the “littleProxy” component but didn”t tried it yet.
Can anyone shed some advice / help / guidance regarding the best approach to solve my problem ?
I would consider whether you are testing the right thing. You don’t need to test proxy servers or Java’s network classes.
Consider this utility type for reading data from a URL:
This can be used as an abstraction layer between your code and Java’s network I/O:
Your tests use this layer to mock out the data:
This saves any mucking around with firewalls etc.
In order for this approach to work you would want to have confidence in a set of recorded transactions from real servers to use in your tests.
This approach can be complemented with a dedicated machine running more comprehensive integration tests.