I am writing unit tests/integration tests that invoke class library that uses HttpsURLConnection
objects. Many times whilst invoking methods on the connection objects through the unit tests, like addRequestProperty
, setDoOutput
, setRequestMethod
I get exceptions like java.lang.IllegalStateException: Already connected
. The behaviour is most likely due to following in the gradle as default values are returned.
testOptions {
unitTests.returnDefaultValues = true
}
See http://tools.android.com/tech-docs/unit-testing-support for more details
The same code works fine in the App. Is there a way to actually use the real HttpsURLConnection object while testing?