The problem below is not caused by Gradle but by a misuse of JUnit.
The following code does not fail with Gradle 1.0-m5 and JUnit 4.10:
import org.junit.Test;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
public class AssumptionTest {
@Test
public void foo() {
assumeTrue(false);
fail("Will not fail.");
}
}
The problem is caused by "extends TestCase", i.e. using JUnit 3.8 functionality.
Assume was added in JUnit 4 so the JUnit38ClassRunner does not know that
AssumptionViolatedException does not imply a fail but should result in an
ignored test instead.
Beside that, one could probably argue that tests ignored due to unmet
assumptions should print something during Gradle build. I like the extreme
noiselessness of Gradle, though.
Cheers,
Joern.
On 30.10.2011, at 23:22, Adam Murdoch wrote:
>
> On 31/10/2011, at 6:15 AM, Andrew Spina wrote:
>
>> I'm exploring Gradle as a replacement for my existing ant build. We have
>> several tests that must be skipped under certain circumstances. We've
>> implemented this using org.junit.Assume. When I run gradle build against a
>> project containing this test:
>>
>> import org.junit.Assume;
>>
>> public class MyAssumptionJUnitTest extends TestCase {
>>
>> public void testAssumeClause(){
>> Assume.assumeTrue( false );
>> }
>>
>> }
>>
>> The build terminates with output like this:
>>
>> :AptHst:testClasses
>> :AptHst:test
>> Test edu.stsci.hst.apt.controller.HstServerAvailabilityJUnitTest FAILED
>> 7 tests completed, 4 failures
>>
>> FAILURE: Build failed with an exception.
>>
>> * What went wrong:
>> Execution failed for task ':AptHst:test'.
>> Cause: There were failing tests. See the report at
>> /Users/spina/Code/apt/StagingGround/AptHst/build/reports/tests.
>>
>>
>> The testing report contains a stack trace like this:
>>
>> org.junit.Assume$AssumptionViolatedException: got: <false>, expected: is
>> <true>
>> at org.junit.Assume.assumeThat(Assume.java:42)
>> at org.junit.Assume.assumeTrue(Assume.java:54)
>> at
>> edu.stsci.util.Assumptions.assumeThatNetworkConnectionAvailable(Assumptions.java:17)
>> at
>> edu.stsci.hst.apt.controller.HstServerAvailabilityJUnitTest.testBot2MassAvailable(HstServerAvailabilityJUnitTest.java:64)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at junit.framework.TestCase.runTest(TestCase.java:168)
>> at junit.framework.TestCase.runBare(TestCase.java:134)
>> at junit.framework.TestResult$1.protect(TestResult.java:110)
>> at junit.framework.TestResult.runProtected(TestResult.java:128)
>> at junit.framework.TestResult.run(TestResult.java:113)
>> at junit.framework.TestCase.run(TestCase.java:124)
>> at junit.framework.TestSuite.runTest(TestSuite.java:232)
>> at junit.framework.TestSuite.run(TestSuite.java:227)
>> at
>> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
>> at
>> org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:51)
>> at
>> org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:63)
>>
>>
>> Is this a known problem? Is it intentional? Can I configure it?
>
> It's not intentional. Could you add a jira issue for this problem?
>
>
> --
> Adam Murdoch
> Gradle Co-founder
> http://www.gradle.org
> VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
> http://www.gradleware.com
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email