mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-25 19:09:03 +00:00
Fix spring test to properly handle failures
Failing test cases weren't not properly handled and instead caused test to break. Added a test case and verified it works for both JUnit and Spock.
This commit is contained in:
committed by
Andy Wilkinson
parent
7e7d4b7d3d
commit
cc92ba1a5c
@@ -0,0 +1,37 @@
|
||||
class FailingJUnitTests {
|
||||
@Test
|
||||
void passingTest() {
|
||||
assertTrue(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
void failureByAssertion() {
|
||||
assertTrue(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
void failureByException() {
|
||||
throw new RuntimeException("This should also be handled")
|
||||
}
|
||||
}
|
||||
|
||||
class FailingSpockTest extends Specification {
|
||||
def "this should pass"() {
|
||||
expect:
|
||||
name.size() == length
|
||||
|
||||
where:
|
||||
name | length
|
||||
"Spock" | 5
|
||||
}
|
||||
|
||||
def "this should fail on purpose as well"() {
|
||||
when:
|
||||
String text = "Greetings"
|
||||
|
||||
then:
|
||||
//throw new RuntimeException("This should fail!")
|
||||
true == false
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user