Skip to content

Commit

Permalink
Added test case validating LambdaTest works
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Dec 8, 2020
1 parent 2ecc814 commit ae1dad4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package lambdatest;

import static de.tobiasroeser.lambdatest.Expect.*;

import org.testng.annotations.*;
import de.tobiasroeser.lambdatest.testng.FreeSpec;


/**
* Test case taken from https://github.com/lefou/LambdaTest#writing-tests-with-lambda-test
*/
public class SimpleLambdaTest extends FreeSpec {
public SimpleLambdaTest() {

test("1 + 1 = 2", () -> {
expectEquals(1 + 1, 2);
});

test("a pending test", () -> pending());

test("divide by zero", () -> {
int a = 2;
int b = 0;
intercept(ArithmeticException.class, () -> {
int c = a / b;
});
});

section("A String should", () -> {
final String aString = "A string";

test("match certain criteria", () -> {
expectString(aString)
.contains("string")
.containsIgnoreCase("String")
.startsWith("A")
.endsWith("ng")
.hasLength(8);
});

test("be not longer than 2", () -> {
expectString(aString).isLongerThan(2);
});
});

test("demo of a fail", () -> {
"yes".equals("yes and no");
});
}
}
19 changes: 10 additions & 9 deletions contrib/testng/test/src/mill/testng/TestNGTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ object TestNGTests extends TestSuite {
override def runClasspath: Target[Seq[PathRef]] = T{super.runClasspath() ++ testngClasspath()}
override def ivyDeps = T{
super.ivyDeps() ++
Agg(ivy"org.testng:testng:6.11",
Agg(
ivy"org.testng:testng:6.11",
ivy"de.tototec:de.tobiasroeser.lambdatest:0.7.0"
)
}
def testFrameworks = T {
Expand Down Expand Up @@ -54,14 +56,13 @@ object TestNGTests extends TestSuite {
result == Seq("mill.testng.TestNGFramework"),
evalCount > 0
)
val evalRes = eval.apply(demo.test.test())
evalRes match {
case Left(Exception(ex, outerStack)) =>
println(outerStack.value.mkString("\t", "\n\t\t", ""))
println(ex.getMessage)
ex.printStackTrace()
case _ => ()
}
}
"Test case lookup from inherited annotations" - workspaceTest(demo) { eval =>
val Right((result, evalCount)) = eval.apply(demo.test.test())
val tres = result.asInstanceOf[(String, Seq[mill.scalalib.TestRunner.Result])]
assert(
tres._2.size == 8
)
}
}
}
Expand Down

0 comments on commit ae1dad4

Please sign in to comment.