-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from giurim/fail-when-beforeafter-fails
fix: report before/after failures and ingnored tests
- Loading branch information
Showing
13 changed files
with
291 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/co/helmethair/scalatest/scala/OptionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package co.helmethair.scalatest.scala; | ||
|
||
import scala.Option; | ||
|
||
public class OptionHelper { | ||
public static <T> T getOrElse(Option<T> option, T defaultValue) { | ||
if (option.isDefined()) { | ||
return option.get(); | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package co.helmethair.scalatest; | ||
|
||
import co.helmethair.scalatest.helper.TestEngineExecutionListener; | ||
import co.helmethair.scalatest.helper.TestHelpers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.platform.engine.EngineDiscoveryRequest; | ||
import org.junit.platform.engine.ExecutionRequest; | ||
import org.junit.platform.engine.TestDescriptor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.spy; | ||
|
||
public class IgnoredTest implements TestHelpers { | ||
@Test | ||
void beforeAllAndAfterEachCalledTest() { | ||
EngineDiscoveryRequest discoveryRequest = createClassDiscoveryRequest("tests.IgnoredTest"); | ||
TestDescriptor discoveredTests = engine.discover(discoveryRequest, engineId); | ||
TestEngineExecutionListener listener = spy(new TestEngineExecutionListener()); | ||
ExecutionRequest executionRequest = new ExecutionRequest(discoveredTests, listener, null); | ||
|
||
Map<String, Integer> calls = new HashMap<String, Integer>() {{ | ||
put("not ignored", 1); | ||
put("ignored", 0); | ||
}}; | ||
|
||
verifyTestExecuteCode(calls, () -> engine.execute(executionRequest)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tests | ||
|
||
import co.helmethair.scalatest.helper.RegisterCall | ||
import org.scalatest.BeforeAndAfter | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class AssumeInBeforeTest extends AnyFunSuite with BeforeAndAfter with RegisterCall { | ||
|
||
before { | ||
assume(false, "this should be aborted") | ||
} | ||
|
||
test("some test") { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package tests | ||
|
||
import co.helmethair.scalatest.helper.RegisterCall | ||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class FailInAfterAllTest extends AnyFunSuite with BeforeAndAfterAll with RegisterCall { | ||
|
||
override def afterAll() { | ||
register("after") | ||
fail() | ||
} | ||
|
||
test("test 1") { | ||
register("test 1 runs") | ||
} | ||
|
||
test("test 2") { | ||
register("test 2 runs") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tests | ||
|
||
import co.helmethair.scalatest.helper.RegisterCall | ||
import org.scalatest.BeforeAndAfter | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class FailInAfterTest extends AnyFunSuite with BeforeAndAfter with RegisterCall { | ||
|
||
after { | ||
register("after") | ||
/* | ||
As per Scalatest, only certain tests causing the test fail in an after block | ||
"We will swallow an exception thrown from the after code if it is not test-aborting | ||
and an exception was already thrown by beforeEach or test itself." | ||
*/ | ||
throw new ThreadDeath {} | ||
} | ||
|
||
test("test") { | ||
register("runs") | ||
} | ||
} |
Oops, something went wrong.