简体   繁体   中英

Grails unit test case showing Completed 0 spock test, 0 failed

I am new to Grails. I am using version 2.2.2 My test cases are not running even it says test cases passed. I get the following message after running the test case.

Resolving [test] dependencies... Resolving [runtime] dependencies... | Compiling 1 source files.
| Error log4j:ERROR Property missing when configuring log4j: grails | Error log4j:ERROR Property missing when configuring log4j: grails | Error log4j:ERROR WARNING: Exception occured configuring log4j logging: null | Completed 0 spock test, 0 failed in 1409ms
| Tests PASSED - view reports in D:\\workspace_idea\\optapp\\target\\test-reports

@TestFor(KpiLog)
@TestMixin(DomainClassUnitTestMixin)
@Mock(KpiLog)
class KpiLogSpec extends Specification {

    void "savelog"() {
        prinln "*********"
        when:
        def kpiLog = new KpiLog(scenarioId: 1, kpiId: 2, deltaKpi: 5)
        kpiLog.save(flush: true)

        then:
        KpiLog.list()!= null
    }

    void testSaveFacebookUser(){
        //given
        def kpiLog = new KpiLog(scenarioId: 1, kpiId: 2, deltaKpi: 5)
        //adminRole.addToPermissions("*:*")
        kpiLog.save()
    }
}

Can some one please tell me what is it that I am doing wrong?

I am running the test case as grails test-app -unit KpiLogSpec

Here is the log4j section from the Config.groovy file

    log4j = {
// Example of changing the log pattern for the default console
// appender:
//
//appenders {
//    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}
debug 'grails.app'
error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
        'org.codehaus.groovy.grails.web.pages', //  GSP
        'org.codehaus.groovy.grails.web.sitemesh', //  layouts
        'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
        'org.codehaus.groovy.grails.web.mapping', // URL mapping
        'org.codehaus.groovy.grails.commons', // core / classloading
        'org.codehaus.groovy.grails.plugins', // plugins
        'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
        'org.springframework',
        'org.hibernate',
        'net.sf.ehcache.hibernate'

appenders {
    console name:'S', layout:pattern(conversionPattern: '%d %-5p %c - %m%n')
    //rollingFile name: 'R', file:'/usr/local/jd/logs/optimizer.log',maxFileSize: '5000000KB'
    rollingFile name: 'R', file:grails.config.logPath, maxFileSize: '5000000KB'
    environments {
        production {
            appender new AWSSNSAppender(
                name:'SNS' ,
                topicName:config.optimizer.snsAppender.topicName,
                topicSubject:config.optimizer.snsAppender.topicSubject,
                awsAccessKey:config.optimizer.aws.accessKey,
                awsSecretKey:config.optimizer.aws.secretKey,
                threshold:Level.toLevel(optimizer.snsAppender.threshold, Level.ERROR)
            )
        }
    }
}
info R: ['NotifierService', 'aggDataStackLog','constraintGroupLog','pageFilterLog','alertDebugLog','dacCacLog','tpFlagExportImportLog','timelog','calculationProgress','dictionaryLog','loginServiceLog', 'calculateScenarioLog','connectionLog','dataLabelServiceLog','cross-section-service','qe-basic-executor-service','qe-plan-enumerator-impl-service','qe-basic-planenum-ssservice','ct-dimension-hierarchy-service','cbRuleLog'],additivity:true
error SNS: ['aggDataStackLog','constraintGroupLog','pageFilterLog','alertDebugLog','dacCacLog','tpFlagExportImportLog','timelog','calculationProgress','dictionaryLog','loginServiceLog', 'calculateScenarioLog','connectionLog','dataLabelServiceLog','cross-section-service','qe-basic-executor-service','qe-plan-enumerator-impl-service','qe-basic-planenum-ssservice','ct-dimension-hierarchy-service','cbRuleLog'],additivity:true
//info SNS: ['aggDataStackLog','calculateScenarioLog']
/*root {
    error 'R'
    additivity = true
}   */

}

Here is the test code which I ran.

  @TestMixin(GrailsUnitTestMixin)
class FooSpec extends Specification {

def setup() {
}

def cleanup() {
}

void "test something"() {
    println "****************testing in real "
    assertTrue(1==1)
}
}

Run the test case like this

grails test-app unit: KpiLog

The important thing is that you use unit: instead of -unit and KpiLog instead of KpiLogSpec

Then do not define the variable log .

def log = new KpiLog(scenarioId: 1, kpiId: 2, deltaKpi: 5)

It is reserved for logging in Grails classes (controllers, services, ...). Rename the variable from log to kpiLog

def kpiLog = new KpiLog(scenarioId: 1, kpiId: 2, deltaKpi: 5)

A simple log configuration can be

log4j = {
    appenders {
        console name: 'stdout', layout: pattern(conversionPattern: '%d [%t] %-5p %c - %m%n')
    }

    error  'org.codehaus.groovy.grails.web.servlet',        // controllers
           'org.codehaus.groovy.grails.web.pages',          // GSP
           'org.codehaus.groovy.grails.web.sitemesh',       // layouts
           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping',        // URL mapping
           'org.codehaus.groovy.grails.commons',            // core / classloading
           'org.codehaus.groovy.grails.plugins',            // plugins
           'org.codehaus.groovy.grails.orm.hibernate',      // hibernate integration
           'org.springframework',
           'org.hibernate',
           'net.sf.ehcache.hibernate'
}

Finally, it is working. It was because of the jar msutil in the lib folder. I got this information from one of my friends that it has some incompatibility. I changed the jar which he sent and things started working.

Thanks a lot saw303 for keeping patience with my questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM