Browse Source

testframework example "ctxmembers"

JNI-96
heck 5 years ago
parent
commit
d3073876b2
  1. 25
      test/java/foundation/pEp/jniadapter/test/framework/examples/ctxmembers/Makefile
  2. 65
      test/java/foundation/pEp/jniadapter/test/framework/examples/ctxmembers/TestMain.java

25
test/java/foundation/pEp/jniadapter/test/framework/examples/ctxmembers/Makefile

@ -0,0 +1,25 @@
include ../Makefile.conf
TEST_UNIT_NAME=ctxmembers
JAVA_CLASSES = \
TestMain.class \
# Use the test framework
JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK)
.PHONY: compile run test clean
all: compile
$(MAKE) run
run: compile
cd $(JAVA_CWD);$(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain
compile: $(JAVA_CLASSES)
%.class: %.java
cd $(JAVA_CWD);pwd;javac $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$<
clean:
rm -f $(JAVA_CLASSES)

65
test/java/foundation/pEp/jniadapter/test/framework/examples/ctxmembers/TestMain.java

@ -0,0 +1,65 @@
package foundation.pEp.jniadapter.test.framework.examples.ctxmembers;
import static foundation.pEp.jniadapter.test.framework.TestLogger.*;
import foundation.pEp.jniadapter.test.framework.*;
// Context member object instantiation
//
// In the Context, do not use member objects like this:
// A a = new A(); // WRONG
// Always, declare them as members and instantiate them in the constructor
// Otherwise, all test contexts in a program partially execute before the test using it is actually being run
// Context init() is part of the test
class HelloWorldTestContext extends AbstractTestContext {
String name;
ExampleCtxMember correct;
ExampleCtxMember incorrect = new ExampleCtxMember(false); // WRONG
@Override
public void init() throws Throwable {
log("HelloWorldTestContext: init() called");
correct = new ExampleCtxMember(true);
name = "UnitTestFrameWorkWithoutAName";
}
}
class TestMain {
public static void main(String[] args) throws Exception {
new TestUnit<HelloWorldTestContext>("Hello World",new HelloWorldTestContext() , ctx -> {
// do stuff using the context
// Test FAILS on unhandled exception, otherwise SUCCESS
log("Hello World from: " + ctx.name);
}).run();
}
}
// Just an example member obj
class ExampleCtxMember {
ExampleCtxMember(boolean correct){
if(correct) {
log("Hya from member obj used correctly");
} else {
log("Hya from member obj used wrong");
}
}
}
Loading…
Cancel
Save