TestCaseimplementations together. A client interacting with the framework could then allow you to filter which tests get run by only running a specific test suite. However, a
TestSuitecan be much more than that as it is a first-class citizen and a fundamental aspect of how the framework operates.
TestSuitethat will instantiate just one of these
Heavyobjects for all of the tests associated to it. Additionally, the
TestSuitewill perform some operation before each test to ensure that the object is properly setup.
#[BeforeAll]Attribute. In that scenario the Attribute was used on a
TestCasewhere this time it is declared on a
TestSuite. There's a couple things to note about this hook though; it isn't a static method and it is run before all associated
TestCaseimplementations are executed. A
TestSuitelives higher up the test hierarchy and therefore so does its hooks!
Heavy, that we make use of later on. This use case, instantiating objects with a heavy initialization cost for later use, is the primary reason for the existence of the test suite functionality! A single
TestSuiteobject is created for all associated tests so that this type of state can be shared.
TestSuitetype. Since a
TestSuitelives higher up if we were to run
BeforeEachit would only execute one time for each
TestCasebut this should run for each test. This hook allows doing just that. We simply get our previously created object and perform some operation on it.
BeforeEachTestand is run after each test is finished processing. This implementation simply frees up whatever resources were being used by
Heavyand ensures that at some point the object gets garbage collected.
TestSuitehas been implemented the appropriate
TestCaseneed to be associated to it. There's currently 2 ways in which to do this. Making a
TestSuitethe default or explicitly declaring on each
TestCasewhat suite it belongs to.
TestCasethat does not explicitly declare a
TestSuiteto be associated to the class being annotated. There can only be 1 default suite at a time. Simply use the
TestCasebelongs to. In this case put the annotation on the
TestCaseand use the
AttachToTestSuiteAttribute. For example...
TestSuitethere is still an instance created and all of the
TestCaseand tests are associated to it. If the parser can't find an explicit
TestSuiteAsyncUnit will create an instance of
ImplicitTestSuiteto use instead. This implementation performs no operations and has no hooks defined.
TestSuitewith custom hooks ensure the ramifications are well understood. With great power comes great responsiblity and implementing an explicit
TestSuite, while sometimes necessary, also brings an additional level of complexity. Make sure you've read over the Hooks reference!