Reputation: 25
Following is my code:
package ro
import org.junit.Test
/**
* Created by roroco on 3/18/15.
*/
class TryTest extends GroovyTestCase {
@Test
def testSmth() {
assert 1 == 1
}
}
and i run it with 'gradle test --tests ro.TryTest', it raise:
ro.TryTest > junit.framework.TestSuite$1.warning FAILED
junit.framework.AssertionFailedError at TestSuite.java:97
1 test completed, 1 failed
:test FAILED
here is source
Upvotes: 0
Views: 15582
Reputation: 171104
Tests need to return void
for GroovyTestCase
, so your test class should be:
package ro
/**
* Created by roroco on 3/18/15.
*/
class TryTest extends GroovyTestCase {
void testSmth() {
assert 1 == 1
}
}
Also, your build.gradle file doesn't need the java
AND groovy
plugins, groovy
imports java
by definition, so your file can be:
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.1'
testCompile 'junit:junit:4.12'
}
As an unrelated aside, I tend to use Spock in place of GroovyTestCase
these days, so if you add:
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
to your dependencies, you can then write Spock tests (this would go in src/test/groovy/ro/TrySpec.groovy
)
package ro
class TrySpec extends spock.lang.Specification {
def 'a simple test'() {
when: 'I have a number'
def number = 1
then: 'It should equal 1'
number == 1
}
}
Upvotes: 4