Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JUnit tests for SingleTestCaseRunner and ParallelTestCaseRunner
- Loading branch information
1 parent
050c2bc
commit 13df6b2
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...-core/src/test/groovy/au/com/ps4impact/madcow/execution/ParallelTestCaseRunnerTest.groovy
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,74 @@ | ||
package au.com.ps4impact.madcow.execution | ||
|
||
import au.com.ps4impact.madcow.MadcowTestCase | ||
import fj.Effect | ||
import fj.P | ||
import fj.P2 | ||
import fj.Unit | ||
import fj.control.parallel.Actor | ||
import fj.control.parallel.Strategy | ||
import fj.data.Option | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class ParallelTestCaseRunnerTest extends GroovyTestCase { | ||
|
||
ArrayList<String> grassScript = new ArrayList<String>() | ||
|
||
ExecutorService pool = Executors.newFixedThreadPool(10) | ||
Strategy<Unit> strategy = Strategy.executorStrategy(pool) | ||
|
||
ConcurrentHashMap exceptions = [:] | ||
AtomicInteger numberOfTestsRan = new AtomicInteger(0) | ||
|
||
def callback = Actor.queueActor(strategy, { P2<MadcowTestCase, Option<Exception>> result -> | ||
numberOfTestsRan.andIncrement; | ||
exceptions.put(result._1(), result._2()) | ||
} as Effect); | ||
|
||
void testTestCaseErrorTrue() { | ||
MadcowTestCase madcowTestCase = new MadcowTestCase("SingleTestCaseRunnerTest-testExecutionException", grassScript) { | ||
@Override | ||
void execute() { | ||
throw new Exception() | ||
} | ||
|
||
@Override | ||
protected void createStepRunner() { | ||
} | ||
} | ||
|
||
executeTest(madcowTestCase) | ||
assertTrue(madcowTestCase.testCaseError == true) | ||
} | ||
|
||
void testTestCaseErrorFalse() { | ||
MadcowTestCase madcowTestCase = new MadcowTestCase("SingleTestCaseRunnerTest-testExecutionException", grassScript) { | ||
@Override | ||
void execute() { | ||
} | ||
|
||
@Override | ||
protected void createStepRunner() { | ||
} | ||
} | ||
|
||
executeTest(madcowTestCase) | ||
assertTrue(madcowTestCase.testCaseError == false) | ||
} | ||
|
||
|
||
private void executeTest(MadcowTestCase madcowTestCase) { | ||
def parallelTestCaseRunner = new ParallelTestCaseRunner(strategy, callback) | ||
try { | ||
parallelTestCaseRunner.act(P.p(madcowTestCase, null)) | ||
} catch(e) {} | ||
|
||
while (numberOfTestsRan.get() < 1) { | ||
Thread.sleep(500); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ow-core/src/test/groovy/au/com/ps4impact/madcow/execution/SingleTestCaseRunnerTest.groovy
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,44 @@ | ||
package au.com.ps4impact.madcow.execution | ||
|
||
import au.com.ps4impact.madcow.MadcowTestCase | ||
import au.com.ps4impact.madcow.report.IMadcowReport | ||
|
||
class SingleTestCaseRunnerTest extends GroovyTestCase { | ||
|
||
ArrayList<String> grassScript = new ArrayList<String>() | ||
|
||
void testTestCaseErrorTrue() { | ||
MadcowTestCase testCase = new MadcowTestCase("SingleTestCaseRunnerTest-testExecutionException", grassScript) { | ||
@Override | ||
void execute() { | ||
throw new Exception() | ||
} | ||
|
||
@Override | ||
protected void createStepRunner() { | ||
} | ||
} | ||
try { | ||
new SingleTestCaseRunner(testCase, new ArrayList<IMadcowReport>()) | ||
} catch(e) {} | ||
|
||
assertTrue(testCase.testCaseError == true) | ||
} | ||
|
||
void testTestCaseErrorFalse() { | ||
MadcowTestCase testCase = new MadcowTestCase("SingleTestCaseRunnerTest-testExecutionException", grassScript) { | ||
@Override | ||
void execute() { | ||
} | ||
|
||
@Override | ||
protected void createStepRunner() { | ||
} | ||
} | ||
try { | ||
new SingleTestCaseRunner(testCase, new ArrayList<IMadcowReport>()) | ||
} catch(e) {} | ||
|
||
assertTrue(testCase.testCaseError == false) | ||
} | ||
} |