我不明白gradle插件块
apply plugin: 'someplugin1'
apply plugin: 'maven'
Run Code Online (Sandbox Code Playgroud)
和其他一个:
plugins {
id 'org.hidetake.ssh' version '1.1.2'
}
Run Code Online (Sandbox Code Playgroud)
在第一个块我们有一些插件名称.在第二个包和版本.我不明白我应该在哪里使用第一块和第二块.
我已经用Kotlin和Junit 5编写了一些基本的单元测试。不幸的是,当我从Intellij IDEA运行它们时,Gradle找不到这些测试。我从Gradle收到消息“找不到给定的测试包括:[de.mhaug.phd.btcwallet.BasicTests]”,从Intellij收到消息“未收到测试事件”。
有趣的是,从命令行使用“ ./gradlew:clean:test”运行该命令可以报告构建成功。但是,我的第一个测试显然是红色的,因此这表明Gradle没有执行它。
我已经尝试使用更详细的输出来运行它,但是没有任何帮助。这是一个最小的(不是)工作示例:
package de.mhaug.phd.btcwallet
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test
class BasicTests {
@Test
fun hey() {
assertEquals(3,1+1)
}
@Test
fun hey2() {
assertFalse(3==1+1)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的build.gradle:
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'de.mhaug.phd'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我想排除软件包中的一些测试用例,以便使用文件中的test任务build.gradle。例如:
apply plugin: 'com.android.library'
test{
exclude '**/calltest/Summary.class'
}
Run Code Online (Sandbox Code Playgroud)
如果同步项目,则会出现以下异常:
* What went wrong:
A problem occurred evaluating project ':SdkModule'.
> Could not find method test() for arguments [build_4g3vf7b615x3x1p7i9ty0pt1l$_run_closure1@73d026ca] on project ':SdkModule' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)
如果我加 apply plugin : 'java'
CONFIGURE FAILED in 1s
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Run Code Online (Sandbox Code Playgroud)
请帮我。
我正在尝试Gradle和jUnit5.除了我不能运行特定的jUnit测试之外,一切正常.当我右键单击测试类时,不会出现"运行'SampleTest'"选项.
我有最新版本的IntelliJ(2016.1.3)Ultimate.这是我的build.gradle档案:
repositories {
mavenCentral()
}
apply plugin: 'java'
version = '1.0.0-SNAPSHOT'
jar {
baseName = 'test-project'
}
dependencies {
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M1'
}
Run Code Online (Sandbox Code Playgroud)
项目结构是标准结构(如Maven).这是一个测试的例子:
package com.test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class SampleTest {
@Test public void sampleTest() {
int test = 1;
Assertions.assertTrue(test == 1);
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
编辑:
Gradle似乎也没有接受我的测试.当我去build/reports/tests/index.html,它表示0测试.
最终编辑:
按照@ dunny的回答,这就是我所做的一切,让一切顺利.我build.gradle像这样修改了我的文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M1'
}
}
repositories {
mavenCentral() …Run Code Online (Sandbox Code Playgroud) 我看到JUnit5已经发布了,我在IntelliJ V2016.2.1中应用并运行了一些测试用例.
所以看下面的截图.

我只有两个问题.
当我在IntelliJ中运行TestCase时,为什么JUnit Jupiter和JUnit Vintage分离?
我可以合并JUnit 4和5 TestResults吗?
如何为 Android 单元测试配置 JUnit 5?我试过:
testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0")
Run Code Online (Sandbox Code Playgroud)
但它不起作用,当我运行以前最简单的单元测试时:
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
Run Code Online (Sandbox Code Playgroud)
我得到错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:31)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:36)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 1
Empty test suite.
Run Code Online (Sandbox Code Playgroud) 我想在Gradle Kotlin DSL中使用内置的JUnit 5,因为在构建过程中我得到了这个警告:
WARNING: The junit-platform-gradle-plugin is deprecated and will be discontinued in JUnit Platform 1.3.
Please use Gradle's native support for running tests on the JUnit Platform (requires Gradle 4.6 or higher):
https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle
Run Code Online (Sandbox Code Playgroud)
这个链接告诉我放
test {
useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)
在我的build.gradle,但是语法是build.gradle.kts什么?
我当前的构建文件是
import org.gradle.api.plugins.ExtensionAware
import org.junit.platform.gradle.plugin.FiltersExtension
import org.junit.platform.gradle.plugin.EnginesExtension
import org.junit.platform.gradle.plugin.JUnitPlatformExtension
group = "com.example"
version = "0.0"
// JUnit 5
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.junit.platform:junit-platform-gradle-plugin:1.2.0")
}
}
apply {
plugin("org.junit.platform.gradle.plugin")
}
// …Run Code Online (Sandbox Code Playgroud) 我想要什么?
我想使用kotlintest运行测试,并且单击了测试类旁边的图标,从而成功地从IntelliJ运行了它们。我的项目中也有JUnit 5测试。我现在开始使用Gradle Kotlin DSL,并且设法运行了check执行JUnit 5任务的Gradle 任务。
问题是什么?
kotlintest测试未运行!似乎它没有被Gradle发现,因为失败的测试使Gradle任务成功。所以,
如何同时使用Gradle Kotlin DSL和JUnit 5运行kotlintest测试?
我尝试了什么?
如何使用Gradle运行kotlintest测试?基本上是问题的旧版本,但是由于使用了不同的技术:JUnit 4和Gradle而不是Gradle Kotlin DSL,已经过时了。我可以找到的所有其他问题是针对JUnit 4还是不带kotlintest的JUnit 5。
项目设置
我正在使用Gradle 4.6。我的测试是
import io.kotlintest.matchers.exactly
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.FunSpec
class KotlinTest: FunSpec() {
init {
testCalculate()
}
/** This failing test will not fail the Gradle check. */
fun testCalculate() = test("one plus one is two") {
(1+1).toDouble() shouldBe exactly(42.0)
}
}
Run Code Online (Sandbox Code Playgroud)
我的build.gradle.kts是
import org.gradle.api.plugins.ExtensionAware
import org.junit.platform.gradle.plugin.FiltersExtension …Run Code Online (Sandbox Code Playgroud) 我的gradle项目使用junit 5,我试图让测试报告显示在我的构建服务器上.XML报告基本上看起来很好 - 它包含所有测试类和方法,但缺少测试方法中打印的stdout/stderr.只有一些CDATA包含测试元数据.
@Test
void testToString() {
System.out.println("Hello world");
...
}
Run Code Online (Sandbox Code Playgroud)
XML报告:
<testcase name="testToString()" classname="com.my.company.PairsTest" time="0.008">
<system-out><![CDATA[
unique-id: [engine:junit-jupiter]/[class:com.my.company.PairsTest]/[method:testToString()]
display-name: testToString()
]]></system-out>
</testcase>
Run Code Online (Sandbox Code Playgroud)
是否有设置告诉gradle插件捕获stdout/stderr?我环顾了一下http://junit.org/junit5/docs/current/user-guide/#running-tests-build但找不到任何内容.
我正在使用org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3和org.junit.jupiter:junit-jupiter-{api,engine}:5.0.0-M3.
gradle ×6
junit ×5
junit5 ×5
kotlin ×3
android ×2
java ×2
build.gradle ×1
groovy ×1
kotlintest ×1
unit-testing ×1