Skip to content

Commit ab44141

Browse files
authored
Merge pull request #529 from qiniu/tests/split-integration-and-unit-tests
分割单元测试用例和集成测试用例,Github Action 只执行单元存储用例
2 parents 6fdd100 + afd2a7a commit ab44141

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1754
-1678
lines changed

.github/workflows/ci-test.yml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11
name: Java CI with Gradle
2-
32
on:
43
push:
54
paths-ignore:
65
- '**.md'
7-
6+
pull_request:
7+
paths-ignore:
8+
- '**.md'
89
jobs:
910
build:
1011
runs-on: ubuntu-latest
11-
12+
permissions:
13+
actions: read
14+
contents: read
15+
security-events: write
16+
strategy:
17+
fail-fast: false
18+
max-parallel: 1
19+
matrix:
20+
java_version: ['8', '11']
1221
steps:
1322
- name: checkout
1423
uses: actions/checkout@v2
15-
16-
- name: Set up JDK 1.8
24+
- name: Set up JDK
1725
uses: actions/setup-java@v1
1826
with:
19-
java-version: 1.8
20-
27+
java-version: ${{ matrix.java_version }}
2128
- name: Grant execute permission for gradlew
2229
run: chmod +x gradlew
23-
24-
- name: Build with Gradle
25-
env:
26-
QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }}
27-
QINIU_LINKING_APPID: ${{ secrets.QINIU_LINKING_APPID }}
28-
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
29-
QINIU_TEST_ENV: travis
30+
- name: Unit Test
3031
run: |
31-
./gradlew build --stacktrace --info
32-
./gradlew test -d
33-
./gradlew jacocoTestReport
34-
35-
- name: Upload coverage to Codecov
36-
uses: codecov/[email protected]
37-
with:
38-
token: ${{secrets.CODECOV_TOKEN}}
39-
file: build/reports/jacoco/test/jacocoTestReport.xml
32+
./gradlew unitTest -d

.github/workflows/codeql-analysis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
21+
jobs:
22+
analyze:
23+
name: Analyze
24+
runs-on: ubuntu-latest
25+
permissions:
26+
actions: read
27+
contents: read
28+
security-events: write
29+
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
language: [ 'java' ]
34+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
35+
# Learn more:
36+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v2
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v1
43+
with:
44+
languages: ${{ matrix.language }}
45+
- name: Autobuild
46+
uses: github/codeql-action/autobuild@v1
47+
- name: Perform CodeQL Analysis
48+
uses: github/codeql-action/analyze@v1

build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ dependencies {
2323
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.4'
2424
implementation 'com.google.code.gson:gson:2.8.5'
2525
testImplementation group: 'com.qiniu', name: 'happy-dns-java', version: '0.1.6'
26-
testImplementation group: 'junit', name: 'junit', version: '4.12'
26+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
27+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
2728
}
2829

30+
test {
31+
useJUnitPlatform()
32+
}
33+
34+
task unitTest(type: Test) {
35+
useJUnitPlatform {
36+
includeTags 'UnitTest'
37+
}
38+
}
2939

3040
task getHomeDir {
3141
doLast {
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
package com.qiniu.common;
22

3-
import junit.framework.TestCase;
4-
import org.junit.Assert;
5-
import org.junit.Test;
63
import test.com.qiniu.TestConfig;
74

5+
import org.junit.jupiter.api.Tag;
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertSame;
9+
import static org.junit.jupiter.api.Assertions.fail;
810
import java.util.HashMap;
911
import java.util.Map;
1012

1113
/**
1214
* Created by Simon on 6/22/16.
1315
*/
14-
public class AutoZoneTest extends TestCase {
16+
public class AutoZoneTest {
1517

1618
@Test
19+
@Tag("IntegrationTest")
1720
public void testHttp() {
1821
Map<String, String[]> cases = new HashMap<String, String[]>();
1922
cases.put(TestConfig.testBucket_z0,
20-
new String[]{"http://up.qiniu.com",
21-
"http://upload.qiniu.com",
22-
"https://up.qbox.me"});
23+
new String[] { "http://up.qiniu.com", "http://upload.qiniu.com", "https://up.qbox.me" });
2324
cases.put(TestConfig.testBucket_na0,
24-
new String[]{"http://up-na0.qiniu.com",
25-
"http://upload-na0.qiniu.com",
26-
"https://up-na0.qbox.me"});
25+
new String[] { "http://up-na0.qiniu.com", "http://upload-na0.qiniu.com", "https://up-na0.qbox.me" });
2726

2827
for (Map.Entry<String, String[]> entry : cases.entrySet()) {
2928
String bucket = entry.getKey();
3029
String[] domains = entry.getValue();
3130
try {
3231
AutoZone zone = AutoZone.instance;
33-
AutoZone.ZoneInfo zoneInfo = zone.queryZoneInfo(TestConfig.testAccessKey,
34-
bucket);
32+
AutoZone.ZoneInfo zoneInfo = zone.queryZoneInfo(TestConfig.testAccessKey, bucket);
3533
assertEquals(zoneInfo.upHttp, domains[0]);
3634
assertEquals(zoneInfo.upBackupHttp, domains[1]);
3735
assertEquals(zoneInfo.upHttps, domains[2]);
@@ -42,24 +40,27 @@ public void testHttp() {
4240
}
4341

4442
@Test
43+
@Tag("IntegrationTest")
4544
public void testHttpFail() {
4645
try {
4746
AutoZone zone = AutoZone.instance;
4847
zone.queryZoneInfo(TestConfig.dummyAccessKey, TestConfig.dummyBucket);
49-
Assert.fail();
48+
fail();
5049
} catch (QiniuException e) {
51-
Assert.assertEquals(e.code(), 612);
50+
assertEquals(e.code(), 612);
5251
}
5352
}
5453

5554
@Test
55+
@Tag("UnitTest")
5656
public void testSplitE() {
5757
String s1 = "bkt:key";
5858
String s2 = "bkt";
59-
Assert.assertEquals(s1.split(":")[0], s2.split(":")[0]);
59+
assertEquals(s1.split(":")[0], s2.split(":")[0]);
6060
}
6161

6262
@Test
63+
@Tag("IntegrationTest")
6364
public void testC1() {
6465
try {
6566
AutoZone.ZoneInfo info = AutoZone.instance.queryZoneInfo(TestConfig.testAccessKey,
@@ -68,17 +69,18 @@ public void testC1() {
6869

6970
AutoZone.ZoneInfo info2 = AutoZone.instance.queryZoneInfo(TestConfig.testAccessKey,
7071
TestConfig.testBucket_z0);
71-
Assert.assertSame(info, info2);
72+
assertSame(info, info2);
7273

7374
} catch (QiniuException e) {
7475
fail(e.response.toString());
7576
}
7677
}
7778

7879
@Test
80+
@Tag("UnitTest")
7981
public void testZ() {
8082
Zone z1 = new Zone.Builder(Zone.zone0()).upHttp("http://uphttp").build();
81-
Assert.assertSame(z1.getUpHttp(null), "http://uphttp");
82-
Assert.assertSame(Zone.zone0().getUpHttp(null), "http://upload.qiniup.com");
83+
assertSame(z1.getUpHttp(null), "http://uphttp");
84+
assertSame(Zone.zone0().getUpHttp(null), "http://upload.qiniup.com");
8385
}
8486
}

0 commit comments

Comments
 (0)