-
Notifications
You must be signed in to change notification settings - Fork 2
Writing Building Blocks
JSystem BB's are simple JUnit tests that can be extended in order to support Jsystem multi-type user service. Traditionally, jsystem tests are Junit 3.x tests, since JSystem 5.1 we support JUnit4 tests. All Jsystem services support Junit3 and JUnit4. New tests should be written in JUnit4.
JUnit 4 brought about a new cleaner style of writing test cases. Tests written in the JUnit 4 style no longer depend on a specific method naming convention (starting each method name with the word test, calling the set up and tear down methods setUp and tearDown). Instead, the user can use annotations to mark methods as tests as well as additional methods to be run before or after test methods. This latest version of JSystem adds s JUnit 4 support. JSystem still supports the Junit 3 test style.
public class MyTestCase extends SystemTestCase {
public MyTestCase() {
super();
setParentFixture(BasicFixture.class);
}
public void setUp() {
report.step("MyTestCase setUp");
}
public void tearDown() {
report.step("MyTestCase tearDown");
}
public void testSomething() {
report.step("Testing something");
}
}
Table 3: JSystem test based on JUnit 3 Code Example
The user can use the cleaner JUnit 4 style in the following manner.
public class MyTestCase extends SystemTestCase4 {
public MyTestCase() {
super();
setParentFixture(BasicFixture.class);
}
@Before
public void before() {
report.step("MyTestCase setUp");
}
@After
public void after() {
report.step("MyTestCase tearDown");
}
@Test
public void something() {
report.step("Testing something");
}
}
Table 4: JUnit MyTestCase Code Example
The changes that were made to the code in transition from JUnit 3 to JUnit 4 style are detailed as follows.
-
The test case class extends the “SystemTestCase4”, instead of the “SystemTestCase”.
-
The @Before and @After annotations mark methods that are run during the test set up and tear down respectively. All the @Before methods are called before each test is run and all the @After methods are called when it ends.
-
Test method names do not need to start with the word test. The test author can name the test as required, as long as the test is annotated with the @Test annotation.
-
Other JUnit 4 annotations:
-
@BeforeClass – will be executed before the @Before annotation
-
@AfterClass - will be executed after the @After annotation
-
@Ignore – test will not be executed
All the old test written in the JUnit 3 style test cases run without any problems. Only tests deriving from “SystemTestCase4” will be treated as JUnit 4 style tests.
###4.3.2 JUnit 3 support for Test Authoring Coding guidelines to write JUnit 3 based tests:
-
Extend the class “junit.framework.SystemTestCase”
-
Follow JUnit coding guidelines and rules.
Later on in this chapter we discuss how to extend Junit class in order to benefit from jsystem services.
Copyright (c) 2021 JSystem Software
- Introduction
- Interface Overview
- Building Blocks
- System Objects
- Framework Services
- Advanced Functionality
- Core System Objects
- Cli (SSH/Telnet/RS323)