Compare commits

...

6 Commits

Author SHA1 Message Date
Ken Naito
1c9e7fc96a
fix: backbutton test code (#1307) 2021-08-02 20:25:04 +09:00
Erisu
5e52b7ee77
fix: logging method 2021-08-02 15:15:27 +09:00
Erisu
f3e98c8651
refactor: rename java_unit_tests command & test runner file 2021-08-02 14:30:25 +09:00
Erisu
bbc9bcae14
refactor: java test runner 2021-08-02 14:30:25 +09:00
Erisu
cd49902ca3
fix: add androidx.test:rules library 2021-08-02 14:30:25 +09:00
Erisu
f4a0e1ec78
ci: add Java instrumentation tests 2021-08-02 14:30:25 +09:00
5 changed files with 26 additions and 11 deletions

View File

@ -12,13 +12,13 @@
],
"scripts": {
"prepare": "cordova-js build > templates/project/assets/www/cordova.js",
"test": "npm run lint && npm run cover && npm run java-unit-tests",
"test": "npm run lint && npm run cover && npm run java-tests",
"lint": "eslint lib spec test \"templates/cordova/**/!(*.*)\"",
"unit-tests": "jasmine --config=spec/unit/jasmine.json",
"cover": "nyc jasmine --config=spec/coverage.json",
"e2e-tests": "jasmine --config=spec/e2e/jasmine.json",
"java-unit-tests": "node test/run_java_unit_tests.js",
"clean:java-unit-tests": "node test/clean.js"
"java-tests": "node test/java_test_runner.js",
"clean:java-tests": "node test/clean.js"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",

View File

@ -56,6 +56,8 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-web:3.1.1', {
exclude group: 'androidx.test.espresso', module: 'androidx.annotation'
})
androidTestImplementation 'androidx.test:rules:1.4.0'
}
repositories {
google()

View File

@ -158,7 +158,7 @@ public class BackButtonMultipageTest {
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
}
private void assertPageSample(String url) {
private void assertPageSample(String url) throws Throwable {
assertEquals(url, mActivity.onPageFinishedUrl.take());
}
}

View File

@ -21,7 +21,7 @@ const fs = require('fs-extra');
const path = require('path');
/**
* This script is to be run manually (e.g. by npm run clean:java-unit-tests) if
* This script is to be run manually (e.g. by npm run clean:java-tests) if
* you want to upgrade gradlew or test its proper generation.
*/

View File

@ -46,9 +46,13 @@ class AndroidTestRunner {
return new ProjectBuilder(this.projectDir).runGradleWrapper('gradle');
}
_log (...args) {
console.log(...[`[${this.testTitle}]`, ...args]);
}
run () {
return Promise.resolve()
.then(_ => console.log(`[${this.testTitle}] Preparing Gradle wrapper for Java unit tests.`))
.then(_ => this._log('Staging Project Files'))
.then(_ => {
// TODO we should probably not only copy these files, but instead create a new project from scratch
fs.copyFileSync(path.resolve(this.projectDir, '../../framework/cdv-gradle-config-defaults.json'), path.resolve(this.projectDir, 'cdv-gradle-config.json'));
@ -57,26 +61,35 @@ class AndroidTestRunner {
path.join(this.projectDir, 'app/src/main/assets/www/cordova.js')
);
})
.then(_ => this._log('Creating Gradle Wrapper'))
.then(_ => this._createProjectBuilder())
.then(_ => this._log('Getting Gradle Wrapper Version Info'))
.then(_ => this._gradlew('--version'))
.then(_ => console.log(`[${this.testTitle}] Gradle wrapper is ready. Running tests now.`))
.then(_ => this._log('Running Java Unit Tests'))
.then(_ => this._gradlew('test'))
.then(_ => console.log(`[${this.testTitle}] Java unit tests completed successfully`));
.then(_ => this._log('Finished Java Unit Test'))
.then(_ => this._log('Running Java Instrumentation Tests'))
.then(_ => this._gradlew('connectedAndroidTest'))
.then(_ => this._log('Finished Java Instrumentation Tests'));
}
}
Promise.resolve()
.then(_ => console.log('Starting to run all android platform tests'))
.then(_ => console.log('Starting Android Platform Java Tests'))
// AndroidX Test
.then(_ => new AndroidTestRunner('AndroidX Project', path.resolve(__dirname, 'androidx')))
.then(test => test.run())
.then(_ => console.log('Finished running all android platform tests'));
.then(_ => console.log('Finished Running Android Platform Java Tests'));
process.on('unhandledRejection', err => {
// If err has a stderr property, we have seen the message already
if (!('stderr' in err)) console.error(err.message);
console.error('JAVA UNIT TESTS FAILED!');
console.error('JAVA TESTS FAILED!');
process.exitCode = err.code || 1;
});