fully support gradle build and test

This commit is contained in:
金戟 2020-12-01 20:20:44 +08:00
parent 472f90e7e4
commit 001001bfd3
4 changed files with 44 additions and 7 deletions

View File

@ -12,9 +12,9 @@ repositories {
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
testImplementation('com.alibaba.testable:testable-processor:0.3.2-SNAPSHOT')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.3.2-SNAPSHOT')
testRuntimeOnly('com.alibaba.testable:testable-agent:0.3.2-SNAPSHOT')
testImplementation('com.alibaba.testable:testable-processor:0.3.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.3.2')
testRuntimeOnly('com.alibaba.testable:testable-agent:0.3.2')
}
test {

View File

@ -0,0 +1,34 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.10"
}
group = "com.alibaba.testable"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.junit.jupiter:junit-jupiter:5.6.2")
testImplementation("com.alibaba.testable:testable-processor:0.3.2")
testAnnotationProcessor("com.alibaba.testable:testable-processor:0.3.2")
testRuntimeOnly("com.alibaba.testable:testable-agent:0.3.2")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
tasks.withType<Test> {
jvmArgs("-javaagent:${classpath.find { it.name.contains("testable-agent") }!!.absolutePath}")
useJUnitPlatform()
}

View File

@ -0,0 +1 @@
rootProject.name = "demo"

View File

@ -60,15 +60,17 @@
<argLine>@{argLine} -javaagent:${settings.localRepository}/com/alibaba/testable/testable-agent/${testable.version}/testable-agent-${testable.version}.jar</argLine>
```
参见项目`java-demo`的[pom.xml](https://github.com/alibaba/testable-mock/blob/master/demo/java-demo/pom.xml)和`kotlin-demo`的[pom.xml](https://github.com/alibaba/testable-mock/blob/master/demo/kotlin-demo/pom.xml)文件。
## 在Gradle项目中使用
在`build.gradle`文件中添加TestableMock依赖
```groovy
dependencies {
testImplementation('com.alibaba.testable:testable-processor:0.3.1')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.3.1')
testRuntimeOnly('com.alibaba.testable:testable-agent:0.3.1')
testImplementation('com.alibaba.testable:testable-processor:0.3.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.3.2')
testRuntimeOnly('com.alibaba.testable:testable-agent:0.3.2')
}
```
@ -80,4 +82,4 @@ test {
}
```
> 注意由于Gradle的构建与测试运行机制与Maven稍有差异当前在Gradle项目里`@PrivateAccessor`注解和`TestableTool.TEST_CASE`功能存在已知BUG其余功能均可正常使用
参见项目`java-demo`的[build.gradle](https://github.com/alibaba/testable-mock/blob/master/demo/java-demo/build.gradle)和`kotlin-demo`的[build.gradle.kts](https://github.com/alibaba/testable-mock/blob/master/demo/kotlin-demo/build.gradle.kts)文件。