Base class for building basic unit tests for MOOSE objects that can live alone (like user objects, etc.) More...
#include <MooseObjectUnitTest.h>
Public Member Functions | |
MooseObjectUnitTest (const std::string &app_name) | |
Protected Member Functions | |
void | buildObjects () |
template<typename T > | |
T & | addObject (const std::string &type, const std::string &name, InputParameters ¶ms) |
Protected Attributes | |
std::unique_ptr< MooseMesh > | _mesh |
std::shared_ptr< MooseApp > | _app |
Factory & | _factory |
std::shared_ptr< FEProblem > | _fe_problem |
Base class for building basic unit tests for MOOSE objects that can live alone (like user objects, etc.)
This class builds the basic objects that are needed in order to test a MOOSE object. Those are a mesh and an FEProblem. To build a unit test, inherit from this class and build your test using the following template:
In your .h file:
class MyUnitTest : public MooseObjectUnitTest { public: MyUnitTest() : MooseObjectUnitTest("MyAppUnitApp") { // if you are using the old registration system, you want to register your objects using this // call. Otherwise, you do not need it. registerObjects(_factory); buildObjects(); }
protected: void registerObjects(Factory & factory) { // register your objects as usual, we have to be in a method like this so that the register // macros work registerUserObject(MyObjectThatIAmTesting); }
void buildObjects() { // build your object like so InputParameters pars = _factory.getValidParams("MyObjectThatIAmTesting"); _fe_problem->addUserObject("MyObjectThatIAmTesting", "fp", uo_pars); _obj = &_fe_problem->getUserObject<MyObjectThatIAmTesting>("fp"); }
// member variable used later in the actual tests const MyObjectThatIAmTesting * _obj; };
In your .C file
TEST_F(MyObjectThatIAmTesting, test) { EXPECT_EQ("testing", _obj->method(par1, par2)); }
NOTE: Testing mesh-bound objects like Kernels, BCs, etc. is not possible with this class.
Definition at line 69 of file MooseObjectUnitTest.h.
|
inline |
app_name | The name of client's application |
Definition at line 75 of file MooseObjectUnitTest.h.
|
protected |
Definition at line 114 of file MooseObjectUnitTest.h.
|
inlineprotected |
Definition at line 82 of file MooseObjectUnitTest.h.
Referenced by MooseObjectUnitTest().
|
protected |
Definition at line 107 of file MooseObjectUnitTest.h.
Referenced by buildObjects().
|
protected |
Definition at line 108 of file MooseObjectUnitTest.h.
Referenced by buildObjects().
|
protected |
Definition at line 109 of file MooseObjectUnitTest.h.
Referenced by addObject(), and buildObjects().
|
protected |
Definition at line 106 of file MooseObjectUnitTest.h.
Referenced by buildObjects().