-
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 #24 from adhie1337/add-more-tests
chore: add more tests
- Loading branch information
Showing
6 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/test/java/co/helmethair/scalatest/AsyncFunSpecTest.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,32 @@ | ||
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.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.spy; | ||
|
||
public class AsyncFunSpecTest implements TestHelpers { | ||
@Test | ||
void areCalledAsynchronouslyTest() { | ||
EngineDiscoveryRequest discoveryRequest = createClassDiscoveryRequest("tests.AsyncFunSpecTest"); | ||
TestDescriptor discoveredTests = engine.discover(discoveryRequest, engineId); | ||
TestEngineExecutionListener listener = spy(new TestEngineExecutionListener()); | ||
ExecutionRequest executionRequest = new ExecutionRequest(discoveredTests, listener, null); | ||
|
||
List<String> calls = Arrays.asList( | ||
"setup", | ||
"runs asynchronously", | ||
"runs again asynchronously", | ||
"cleanup" | ||
); | ||
|
||
verifyTestExecuteCode(calls, () -> engine.execute(executionRequest)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/co/helmethair/scalatest/OneInstancePerTestTest.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,27 @@ | ||
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.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.spy; | ||
|
||
public class OneInstancePerTestTest implements TestHelpers { | ||
@Test | ||
void areCalledFromOtherInstancesTest() { | ||
EngineDiscoveryRequest discoveryRequest = createClassDiscoveryRequest("tests.OneInstancePerTestTest"); | ||
TestDescriptor discoveredTests = engine.discover(discoveryRequest, engineId); | ||
TestEngineExecutionListener listener = spy(new TestEngineExecutionListener()); | ||
ExecutionRequest executionRequest = new ExecutionRequest(discoveredTests, listener, null); | ||
|
||
List<String> calls = Arrays.asList("2", "3"); | ||
|
||
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
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,37 @@ | ||
package tests | ||
|
||
import co.helmethair.scalatest.helper.RegisterCall | ||
import org.scalatest.{ FutureOutcome, OneInstancePerTest } | ||
import org.scalatest.funspec.AsyncFunSpec | ||
|
||
import scala.concurrent.Future | ||
|
||
class AsyncFunSpecTest extends AsyncFunSpec with RegisterCall with OneInstancePerTest { | ||
|
||
override def withFixture(test: NoArgAsyncTest): FutureOutcome = { | ||
register("setup") | ||
complete { | ||
super.withFixture(test) // Invoke the test function | ||
} lastly { | ||
register("cleanup") | ||
} | ||
} | ||
|
||
describe("AsyncTestSuite") { | ||
it("runs first") { | ||
Future { | ||
Thread.sleep(2000) | ||
register("runs asynchronously") | ||
assert(true) | ||
} | ||
} | ||
|
||
it("runs second") { | ||
Future { | ||
Thread.sleep(1000) | ||
register("runs again asynchronously") | ||
assert(true) | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
package tests | ||
|
||
import co.helmethair.scalatest.helper.RegisterCall | ||
import org.scalatest.OneInstancePerTest | ||
import org.scalatest.funspec.AnyFunSpec | ||
|
||
class OneInstancePerTestTest extends AnyFunSpec with RegisterCall with OneInstancePerTest { | ||
|
||
private val id: Int = OneInstancePerTestTest.nextId | ||
|
||
describe("OneInstancePerTest") { | ||
it("runs first") { | ||
register(id.toString) | ||
} | ||
|
||
it("runs second") { | ||
register(id.toString) | ||
} | ||
} | ||
} | ||
|
||
object OneInstancePerTestTest { | ||
var id: Int = 0 | ||
|
||
def nextId: Int = { | ||
id = id + 1 | ||
id | ||
} | ||
} |