Base class for building basic unit tests for MOOSE actions. More...
#include <ActionUnitTest.h>
Public Member Functions | |
| ActionUnitTest (const std::string &app_name) | |
| void | SetUp () override |
Protected Member Functions | |
| virtual void | buildActions ()=0 |
| Override this to create the action(s) you want to test. More... | |
| void | buildMinimalObjects () |
| Some base objects we often need to have the action act on them. More... | |
| virtual void | runActions ()=0 |
| Override this to make the actions execute NOTE: many tasks will auto-register their task at creation, but for the others, do not forget to register them. More... | |
| template<typename T > | |
| T & | addObject (const std::string &type, const std::string &name, InputParameters ¶ms) |
| Convenience routine for adding an object in an Actions test. More... | |
Protected Attributes | |
| std::unique_ptr< MooseMesh > | _mesh |
| std::shared_ptr< MooseApp > | _app |
| Factory & | _factory |
| ActionFactory & | _action_factory |
| std::shared_ptr< FEProblem > | _fe_problem |
Base class for building basic unit tests for MOOSE actions.
This class follows the classic actions that are needed in order to build a simulation. To build a unit test, inherit from this class and build your test using the following template:
In your .h file:
class MyUnitTest : public ActionUnitTest { public: MyUnitTest() : ActionUnitTest("MyAppUnitApp") { buildAction(); }
protected:
void buildActions() { // Start with the validParams InputParameters pars = _action_factory.getValidParams("MyActionThatIAmTesting"); // Set the parameters you need pars.set<bool>("do this thing") = true; // Build the action into the action warehouse (just like a meta-action would do)
}
void runActions() { // NOTE: if multiple tasks are required, you have to code them here
const auto task_name = "name of the task we want to test the action on"; // Add the task: only needed if the task does not auto-register // Check that the task is registered mooseAssert(_action_factory.isRegisteredTask(task_name), "Should have registered the task"); // Run the task _app->actionWarehouse().executeActionsWithAction(task_name); }
// member variable used later in the actual tests const MyActionIAmTesting * _action; };
In your .C file
TEST_F(MyActionThatIAmTesting, name of the test) { // Testing individual methods EXPECT_EQ("testing", _action->method(par1, par2)); // Testing if an object has been created by action (if stored in the problem) EXPECT_EQ(true, _fe_problem->hasObjectType(name, 0)); }
NOTE: Testing complex actions that build on other actions may require a deep knowledge of the setup phase in MOOSE. Use Debug/show_actions on a regular simulation to get more information on the setup
Definition at line 78 of file ActionUnitTest.h.
|
inline |
| app_name | The name of client's application |
Definition at line 84 of file ActionUnitTest.h.
|
protected |
Convenience routine for adding an object in an Actions test.
Definition at line 144 of file ActionUnitTest.h.
|
protectedpure virtual |
Override this to create the action(s) you want to test.
Referenced by SetUp().
|
inlineprotected |
Some base objects we often need to have the action act on them.
Definition at line 103 of file ActionUnitTest.h.
Referenced by ActionUnitTest().
|
protectedpure virtual |
Override this to make the actions execute NOTE: many tasks will auto-register their task at creation, but for the others, do not forget to register them.
To check if a task is registered, use: _action_factory.isRegisteredTask("auto_checkpoint_action")
Referenced by SetUp().
|
inlineoverride |
Definition at line 92 of file ActionUnitTest.h.
|
protected |
Definition at line 138 of file ActionUnitTest.h.
|
protected |
Definition at line 136 of file ActionUnitTest.h.
Referenced by buildMinimalObjects().
|
protected |
Definition at line 137 of file ActionUnitTest.h.
Referenced by buildMinimalObjects().
|
protected |
Definition at line 139 of file ActionUnitTest.h.
Referenced by addObject(), and buildMinimalObjects().
|
protected |
Definition at line 135 of file ActionUnitTest.h.
Referenced by buildMinimalObjects().
1.8.14