我们刚开始在我们的项目中使用Gradle和TestNG,所以我正在检查是否实际上没有任何测试失败.我很惊讶地看到它没有.测试被选中并正确编译,所以我看到了类文件.我也得到了一个关于跑步的报告,但它说了0次测试(预计2次).运行gradle clean test -i给出了以下内容:
:contentplatform-service:compileTestJava (Thread[Daemon worker Thread 7,5,main])
 started.
:contentplatform-service:compileTestJava
Executing task ':contentplatform-service:compileTestJava' (up-to-date check took
 0.08 secs) due to:
  Output file D:\Dev\contentplatform-service\build\classes\test has changed.
  Output file D:\Dev\contentplatform-service\build\dependency-cache has changed.

  Output file D:\Dev\contentplatform-service\build\classes\test\nl\xillio\conten
tplatform\service\SuperSimpleTest.class has been removed.
All input files are considered out-of-date for incremental task ':contentplatfor
m-service:compileTestJava'.
Compiling with JDK Java compiler API.
:contentplatform-service:compileTestJava (Thread[Daemon worker Thread 7,main])
 completed. Took 0.229 secs.
:contentplatform-service:processtestResources (Thread[Daemon worker Thread 7,m
ain]) started.
:contentplatform-service:processtestResources
Skipping task ':contentplatform-service:processtestResources' as it has no sourc
e files.
:contentplatform-service:processtestResources UP-TO-DATE
:contentplatform-service:processtestResources (Thread[Daemon worker Thread 7,m
ain]) completed. Took 0.001 secs.
:contentplatform-service:testClasses (Thread[Daemon worker Thread 7,main]) sta
rted.
:contentplatform-service:testClasses
Skipping task ':contentplatform-service:testClasses' as it has no actions.
:contentplatform-service:testClasses (Thread[Daemon worker Thread 7,main]) com
pleted. Took 0.001 secs.
:contentplatform-service:test (Thread[Daemon worker Thread 7,main]) started.
:contentplatform-service:test
Executing task ':contentplatform-service:test' (up-to-date check took 0.049 secs
) due to:
  Output file D:\Dev\contentplatform-service\build\test-results\binary\test has
changed.
  Output file D:\Dev\contentplatform-service\build\test-results has changed.
  Output file D:\Dev\contentplatform-service\build\reports\tests has changed.
Finished generating test XML results (0.0 secs) into: D:\Dev\contentplatform-ser
vice\build\test-results
Generating HTML test report...
Finished generating test html results (0.014 secs) into: D:\Dev\contentplatform-
service\build\reports\tests
:contentplatform-service:test (Thread[Daemon worker Thread 7,main]) completed.
 Took 0.194 secs.

SuperSimpleTest.java:

package nl.xillio.contentplatform.service;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@Test
public class SuperSimpleTest {

    @BeforeClass
    public void setUp() {
        // code that will be invoked when this test is instantiated
    }

    @Test
    public void testtest() {
        Assert.assertEquals(true,true);
    }
}

build.gradle包含:

test {
    // enable TestNG support (default is JUnit)
    useTestNG()
    scanForTestClasses = false  
    include '**/*'

    testLogging {
        showStandardStreams = true

        // log results to "build/test-results" directory
        exceptionFormat "full"
        events "started","passed","skipped","Failed","standardOut","standardError"
    }
}

我已经看过关于这个主题的other questions了,在那里我发现使用scanForTestClasses = false作为解决方法的提示(见https://issues.gradle.org/browse/GRADLE-1682).但是,这个问题似乎无关紧要.我在这里犯了一些其他的菜鸟错误吗?如何才能让SuperSimpleTest执行?

更新:我试图强制gradle运行一个特定的测试,结果是一个有趣的错误:Gradle complains about JUnit version on TestNG task

解决方法

这确实是一个愚蠢的noob错误.我们正在使用一个多项目设置,其中包含一个主项目和同一级别的几个文件夹,其中包含代码和测试.我意外使用的build.gradle只配置了主项目以使用TestNG.解决方案是将测试目标包含在allprojects或子项目闭包中.这里解释的是: What is the difference between allprojects and subprojects

所以这是工作build.gradle:

def mainClassName = 'nl.xillio.contentplatform.view.Run'


// Load settings for all projects including master and subprojects
allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'

    version '0.1'

    repositories {
        mavenCentral()
        maven {
            url 'http://mvnrepository.com/maven2'
        }
        maven {
            url 'http://download.java.net/maven/2'
        }
    }
}

// Load the dependencies for all subprojects (layers)
subprojects {
    dependencies {
    //to do: move these to the correct subprojects
        compile 'javax.inject:javax.inject:1'
        compile 'org.springframework:spring-context:4.1.4.RELEASE'
        compile 'org.springframework:spring-core:4.1.4.RELEASE'
        compile 'org.springframework:spring-beans:4.1.4.RELEASE'
        compile 'commons-logging:commons-logging:1.2'
        testCompile 'org.springframework:spring-test:4.1.4.RELEASE'
        testCompile 'org.testng:testng:6.1.1'
    }

    test {
        // enable TestNG support (default is JUnit)
        useTestNG() 
    }
}

// Resolve the dependencies between the layers in the individual project's build.gradle files
// add ONLY specific per project behavIoUr of the GLOBAL build here:

project(':contentplatform-web') {
}

project(':contentplatform-service') {
}

project(':contentplatform-dao') {
}

// Return a list of all the external libraries
def getLibraries() {
    return configurations.runtime.filter{!it.name.startsWith('contentplatform')}
}

// copy all the libraries to a libs folder
task copyLibraries(type: copy) {
    group 'Content Platform'
    description 'copy all the external libraries to the /libs folder.'

    destinationDir file('./build/')

    into('libs/') {
        from getLibraries()
    }
}

// Perform the build task before building the big jar
jar {
    group 'Content Platform'
    description 'Package all the layers and dependencies into a big jar.'

    // The libraries are required to build
    dependsOn(copyLibraries)

    // The final big jar needs all the layers
    dependencies {
        compile project(':contentplatform-web'),project(':contentplatform-dao'),project(':contentplatform-service'),project(':contentplatform-model')
    }
    // Create a MANIFEST.MF file,the main class file is in the web layer
    manifest {
        attributes 'Implementation-Title': 'Content Platform','Implementation-Version': version,'Built-By': System.getProperty('user.name'),'Built-Date': new Date(),'Built-JDK': System.getProperty('java.version'),'Class-Path': getLibraries().collect{'../libs/' + it.getName()}.join(' '),'Main-Class': mainClassName
    }

    // Include the layers in the fat jar
    from(configurations.compile.filter{it.name.startsWith('contentplatform')}.collect{it.isDirectory() ? it : zipTree(it) }) {
        exclude "meta-inf/*.SF"
        exclude "meta-inf/*.DSA"
        exclude "meta-inf/*.RSA"
    }

    // Save the fat jar in the root of the folder instead of in build/libs
    destinationDir file('.')
}

java – Gradle编译但不运行TestNG测试的更多相关文章

  1. iOS 10 Safari问题在DOM中不再包含元素

    使用此链接,您可以重现该错误.https://jsfiddle.net/pw7e2j3q/如果您点击元素并从dom中删除它,然后单击链接测试.你应该看到旧的元素弹出选择.是否有一些黑客来解决这个问题?解决方法我能够重现这个问题.问题是,每当您尝试删除其更改事件上的选择框时,iOS10都无法正确解除对选择框的绑定.要解决此问题,您需要将代码更改事件代码放在具有一些超时

  2. ios – 有没有办法针对存档版本(.ipa)运行XCTest(UI)?

    要么我们可以单独构建和测试,以便我们可以先构建并在以后对该构建进行测试吗?

  3. ios – Xcode 5持续集成CodeSign失败

    嗨,您好.我正在尝试使用xcode5和OSXServer为我的iOS应用程序配置持续集成.我将证书和p12添加到系统KeyChain,我还将配置文件复制到配置文件的服务器文件夹.集成失败,日志显示错误消息短消息:Command/usr/bin/codesignFailedwithexitcode1完整信息:CodeSign/Library/Server/Xcode/Data/BotRuns/Cac

  4. ios app如何“知道”运行单元测试

    我知道我可以用xcodebuild开始我的应用程序的单元测试,但我想知道是什么告诉应用程序在启动期间运行测试,它是一个发送到应用程序的特殊参数,还是以不同的方式编译以运行测试?

  5. ios – 如何在Swift中正确转换为子类?

    我有一个带有许多不同单元格的UITableView,基于数据源内容数组中的内容,它们应该显示自定义内容.在这里我得到了错误UITableViewCell没有属性customLabelQuestionTableViewCell有哪些.我的演员到QuestionTableViewCell有什么问题?解决方法问题不是你的演员,而是你的细胞宣言.您将其声明为可选的UITableViewCell,并且该声明

  6. ios – Swift 2.0 – Google Analytics事件构建器错误 – NSMutableDictionary无法转换为[NSObject:AnyObject]

    完美地使用Swift1.2代码:错误:任何的想法?解决方法你错了你的事件.这是正确的方法和一种方法.将事件跟踪器初始化为NSObject在发送方法中将NSObject转换为Anyobject.

  7. xcode – 添加OCMock会导致Test启动主应用程序而不是运行测试

    我正在尝试将Ocmock添加到我现有的Cocoa项目中,但我遇到了一个我没有看到其他人覆盖的奇怪问题.我最终将它分离到以下内容:如果我只是将Ocmock.framework引用添加到我的项目中(即以某种方式将其拖到LinkBinaryWithLibraries构建阶段),当我运行测试时,真正的应用程序将被启动.没有Ocmock,输出正常:使用Ocmock框架链接(部分输出):此后,其他应用程序输出

  8. Xcode:用于条件DEBUG / TEST代码的预处理器宏

    我在我的代码(例如AppDelegate.m)中有不应该为单元测试编译的部分,例如当您在创建新项目时选择“添加单元测试”时,目标是由Xcode设置的.在项目文件中,我已将标志CONfigURATION_TESTS添加到内置目标的MyAppTests的预处理器宏中,但未添加到MyApp目标.这是我发现的许多帖子中的建议方式.但是这不起作用,因为(我猜)MyAppTests目标将MyApp目标作为依赖

  9. ios – 如何存档包含自定义框架的应用程序?

    我有一个我创建的xcode框架项目,我可以编译成一个myframework.framework文件.编译之后,我将这个框架拖到我应用程序的Frameworks项目文件夹中,然后利用框架中的类,将适当的import语句添加到需要它的任何类;这允许我的应用程序成功编译与在框架中定义的类的引用.要使应用程序成功部署到我的设备,我还将我的自定义框架添加到我的目标的“嵌入式二进制文件”部分.有了这一切,我可

  10. ios – 1个用于体系结构x86_64的重复符号

    我不确定我做错了什么.我将项目文件夹移动到另一个文件夹,并将备份文件夹复制到桌面.我试图打开备份项目并构建,我收到了链接器错误.所以我决定删除备份文件夹并将项目文件夹移回桌面.我不能再编译并收到以下错误.没有派生数据文件夹还是一样1.我打开了DerivedData文件夹并删除了其中的所有内容2.我删除了所有模拟器中的所有项目3.我重新启动了xCode,Clean和build还是一样将项目添加到Gi

随机推荐

  1. 基于EJB技术的商务预订系统的开发

    用EJB结构开发的应用程序是可伸缩的、事务型的、多用户安全的。总的来说,EJB是一个组件事务监控的标准服务器端的组件模型。基于EJB技术的系统结构模型EJB结构是一个服务端组件结构,是一个层次性结构,其结构模型如图1所示。图2:商务预订系统的构架EntityBean是为了现实世界的对象建造的模型,这些对象通常是数据库的一些持久记录。

  2. Java利用POI实现导入导出Excel表格

    这篇文章主要为大家详细介绍了Java利用POI实现导入导出Excel表格,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  3. Mybatis分页插件PageHelper手写实现示例

    这篇文章主要为大家介绍了Mybatis分页插件PageHelper手写实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  4. (jsp/html)网页上嵌入播放器(常用播放器代码整理)

    网页上嵌入播放器,只要在HTML上添加以上代码就OK了,下面整理了一些常用的播放器代码,总有一款适合你,感兴趣的朋友可以参考下哈,希望对你有所帮助

  5. Java 阻塞队列BlockingQueue详解

    本文详细介绍了BlockingQueue家庭中的所有成员,包括他们各自的功能以及常见使用场景,通过实例代码介绍了Java 阻塞队列BlockingQueue的相关知识,需要的朋友可以参考下

  6. Java异常Exception详细讲解

    异常就是不正常,比如当我们身体出现了异常我们会根据身体情况选择喝开水、吃药、看病、等 异常处理方法。 java异常处理机制是我们java语言使用异常处理机制为程序提供了错误处理的能力,程序出现的错误,程序可以安全的退出,以保证程序正常的运行等

  7. Java Bean 作用域及它的几种类型介绍

    这篇文章主要介绍了Java Bean作用域及它的几种类型介绍,Spring框架作为一个管理Bean的IoC容器,那么Bean自然是Spring中的重要资源了,那Bean的作用域又是什么,接下来我们一起进入文章详细学习吧

  8. 面试突击之跨域问题的解决方案详解

    跨域问题本质是浏览器的一种保护机制,它的初衷是为了保证用户的安全,防止恶意网站窃取数据。那怎么解决这个问题呢?接下来我们一起来看

  9. Mybatis-Plus接口BaseMapper与Services使用详解

    这篇文章主要为大家介绍了Mybatis-Plus接口BaseMapper与Services使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  10. mybatis-plus雪花算法增强idworker的实现

    今天聊聊在mybatis-plus中引入分布式ID生成框架idworker,进一步增强实现生成分布式唯一ID,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

返回
顶部