mirror of
https://github.com/square/okhttp.git
synced 2025-11-05 12:17:34 +08:00
Regression Test Module (#6412)
This commit is contained in:
@@ -146,6 +146,7 @@ ext.applyOsgi = { project ->
|
||||
subprojects { project ->
|
||||
if (project.name == 'android-test') return
|
||||
if (project.name == 'okhttp-bom') return
|
||||
if (project.name == 'regression-test') return
|
||||
|
||||
apply plugin: "org.jetbrains.kotlin.jvm"
|
||||
apply plugin: 'java'
|
||||
|
||||
55
regression-test/README.md
Normal file
55
regression-test/README.md
Normal file
@@ -0,0 +1,55 @@
|
||||
Regression Test
|
||||
===============
|
||||
|
||||
A gradle module for running Regression tests on a device, emulator or JVM.
|
||||
|
||||
1. Add an Emulator named `pixel5`, if you don't already have one
|
||||
|
||||
```
|
||||
$ sdkmanager --install "system-images;android-29;google_apis;x86"
|
||||
$ echo "no" | avdmanager --verbose create avd --force --name "pixel5" --device "pixel" --package "system-images;android-29;google_apis;x86" --tag "google_apis" --abi "x86"
|
||||
```
|
||||
|
||||
2. Run an Emulator using Android Studio or from command line.
|
||||
|
||||
```
|
||||
$ emulator -no-window -no-snapshot-load @pixel5
|
||||
```
|
||||
|
||||
2. Turn on logs with logcat
|
||||
|
||||
```
|
||||
$ adb logcat '*:E' OkHttp:D Http2:D TestRunner:D TaskRunner:D OkHttpTest:D GnssHAL_GnssInterface:F DeviceStateChecker:F memtrack:F
|
||||
...
|
||||
01-01 12:53:32.811 10999 11089 D OkHttp : [49 ms] responseHeadersEnd: Response{protocol=h2, code=200, message=, url=https://1.1.1.1/dns-query?dns=AAABAAABAAAAAAAAA3d3dwhmYWNlYm9vawNjb20AABwAAQ}
|
||||
01-01 12:53:32.811 10999 11089 D OkHttp : [49 ms] responseBodyStart
|
||||
01-01 12:53:32.811 10999 11089 D OkHttp : [49 ms] responseBodyEnd: byteCount=128
|
||||
01-01 12:53:32.811 10999 11089 D OkHttp : [49 ms] connectionReleased
|
||||
01-01 12:53:32.811 10999 11089 D OkHttp : [49 ms] callEnd
|
||||
01-01 12:53:32.816 10999 11090 D OkHttp : [54 ms] responseHeadersStart
|
||||
01-01 12:53:32.816 10999 11090 D OkHttp : [54 ms] responseHeadersEnd: Response{protocol=h2, code=200, message=, url=https://1.1.1.1/dns-query?dns=AAABAAABAAAAAAAAA3d3dwhmYWNlYm9vawNjb20AAAEAAQ}
|
||||
01-01 12:53:32.817 10999 11090 D OkHttp : [55 ms] responseBodyStart
|
||||
01-01 12:53:32.818 10999 11090 D OkHttp : [56 ms] responseBodyEnd: byteCount=128
|
||||
01-01 12:53:32.818 10999 11090 D OkHttp : [56 ms] connectionReleased
|
||||
01-01 12:53:32.818 10999 11090 D OkHttp : [56 ms] callEnd
|
||||
```
|
||||
|
||||
3. Run tests using gradle
|
||||
|
||||
```
|
||||
$ ANDROID_SDK_ROOT=/Users/myusername/Library/Android/sdk ./gradlew :regression-test:connectedCheck
|
||||
...
|
||||
> Task :regression-test:connectedDebugAndroidTest
|
||||
...
|
||||
11:55:40 V/InstrumentationResultParser: Time: 13.271
|
||||
11:55:40 V/InstrumentationResultParser:
|
||||
11:55:40 V/InstrumentationResultParser: OK (12 tests)
|
||||
...
|
||||
11:55:40 I/XmlResultReporter: XML test result file generated at /Users/myusername/workspace/okhttp/regression-test/build/outputs/regression-results/connected/TEST-pixel3a-Q(AVD) - 10-android-test-.xml. Total tests 13, passed 11, assumption_failure 1, ignored 1,
|
||||
...
|
||||
BUILD SUCCESSFUL in 1m 30s
|
||||
63 actionable tasks: 61 executed, 2 up-to-date
|
||||
|
||||
```
|
||||
|
||||
n.b. use ANDROID_SERIAL=emulator-5554 or similar if you need to select between devices.
|
||||
50
regression-test/build.gradle
Normal file
50
regression-test/build.gradle
Normal file
@@ -0,0 +1,50 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'org.jetbrains.kotlin.android'
|
||||
|
||||
repositories {
|
||||
jcenter {
|
||||
// Required for a dependency of Android lint.
|
||||
content {
|
||||
includeGroup 'org.jetbrains.trove4j'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
// issue merging due to conflict with httpclient and something else
|
||||
exclude("META-INF/DEPENDENCIES")
|
||||
}
|
||||
|
||||
compileSdkVersion 30
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunnerArguments(['notClass': 'org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter,org.bouncycastle.pqc.crypto.qtesla.QTeslaKeyEncodingTests'])
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
|
||||
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
|
||||
implementation "com.squareup.okhttp3:okhttp:3.12.12"
|
||||
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.12.12")
|
||||
androidTestImplementation "org.bouncycastle:bcprov-jdk15to18:${versions.bouncycastle}"
|
||||
androidTestImplementation "org.bouncycastle:bctls-jdk15to18:${versions.bouncycastle}"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
androidTestImplementation 'org.apache.httpcomponents.client5:httpclient5:5.0'
|
||||
androidTestImplementation 'com.squareup.moshi:moshi:1.11.0'
|
||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.11.0'
|
||||
}
|
||||
1
regression-test/settings.gradle
Normal file
1
regression-test/settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
project.name = 'regression-test'
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Square, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package okhttp.regression;
|
||||
|
||||
import android.os.Build
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.Request
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import javax.net.ssl.SSLHandshakeException
|
||||
|
||||
/**
|
||||
* Let's Encrypt expiring root test.
|
||||
*
|
||||
* Read https://community.letsencrypt.org/t/mobile-client-workarounds-for-isrg-issue/137807
|
||||
* for background.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class LetsEncryptTest {
|
||||
private var client = OkHttpClient()
|
||||
|
||||
@Test fun getFailsWithoutAdditionalCert() {
|
||||
val androidMorEarlier = Build.VERSION.SDK_INT <= 23
|
||||
try {
|
||||
val request = Request.Builder()
|
||||
.url("https://valid-isrgrootx1.letsencrypt.org/robots.txt")
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
assertEquals(404, response.code())
|
||||
assertEquals(Protocol.HTTP_2, response.protocol())
|
||||
}
|
||||
if (androidMorEarlier) {
|
||||
fail()
|
||||
}
|
||||
} catch (sslhe: SSLHandshakeException) {
|
||||
assertTrue(androidMorEarlier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package okhttp.android.test.compare;
|
||||
package okhttp.regression.compare;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients
|
||||
import org.apache.hc.core5.http.HttpVersion
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@@ -41,9 +41,9 @@ class ApacheHttpClientTest {
|
||||
val request = HttpGet("https://google.com/robots.txt")
|
||||
|
||||
httpClient.execute(request).use { response ->
|
||||
assertThat(response.code).isEqualTo(200)
|
||||
// TODO reenable ALPN later
|
||||
assertThat(response.version).isEqualTo(HttpVersion.HTTP_1_1)
|
||||
assertEquals(200, response.code)
|
||||
// TODO enable ALPN later
|
||||
assertEquals(HttpVersion.HTTP_1_1, response.version)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package okhttp.android.test.compare;
|
||||
package okhttp.regression.compare;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.Request
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@@ -37,8 +37,8 @@ class OkHttpClientTest {
|
||||
.url("https://google.com/robots.txt")
|
||||
.build()
|
||||
client.newCall(request).execute().use { response ->
|
||||
assertThat(response.code).isEqualTo(200)
|
||||
assertThat(response.protocol).isEqualTo(Protocol.HTTP_2)
|
||||
assertEquals(200, response.code())
|
||||
assertEquals(Protocol.HTTP_2, response.protocol())
|
||||
}
|
||||
}
|
||||
}
|
||||
4
regression-test/src/main/AndroidManifest.xml
Normal file
4
regression-test/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="okhttp.regression">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
3
regression-test/src/main/res/values/strings.xml
Normal file
3
regression-test/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">regression-test</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<base-config cleartextTrafficPermitted="false">
|
||||
</base-config>
|
||||
</network-security-config>
|
||||
@@ -9,6 +9,7 @@ if (properties.containsKey('android.injected.invoked.from.ide') ||
|
||||
System.getenv('ANDROID_SDK_ROOT') != null) {
|
||||
// Currently incompatible with Intellij, use with Android Studio and from CLI with explicit flag
|
||||
include ':android-test'
|
||||
include ':regression-test'
|
||||
}
|
||||
|
||||
include ':native-image-tests'
|
||||
|
||||
Reference in New Issue
Block a user