tiebin-zhang / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

AssertionError not rethrown #377

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create the following test class (also see attachment):
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest
public class TestAssertionErrorRethrownTest {

    @Test(expected = AssertionError.class)
    public void testSomething() {
        assert false;
    }

}

2. Run the test with the -ea JVM switch.

What is the expected output? What do you see instead?
I expect the test to pass. Instead, I see the following message:
  testSomething(TestAssertionErrorRethrownTest): Expected exception: java.lang.AssertionError

What version of the product are you using? On what operating system?
Relevant POM file dependencies:
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.4.11</version>
            <scope>test</scope>
        </dependency>

Please provide any additional information below.
Commenting out the (normally useful, i.e. with classes to prepare) 
@PrepareForTest annotation makes the test succeed.

Original issue reported on code.google.com by drvdijk on 12 Mar 2012 at 11:20

Attachments:

GoogleCodeExporter commented 9 years ago
A work-around to this issue is to configure assertions in Maven as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <!-- This does the trick -->
                <argLine>-ea</argLine>
            </configuration>
          </plugin>
    </plugins>
</build>

Beware: using the tag <enableAssertions> does NOT work.

Original comment by willianc...@gmail.com on 15 Jul 2015 at 1:50