Skip to content

Commit

Permalink
Add testing skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
einar90 committed Sep 15, 2015
1 parent 56ab148 commit 6460fd6
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
3 changes: 2 additions & 1 deletion FieldOpt/FieldOpt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CONFIG += c++11
SUBDIRS = \
src \
Console \ #\
ERTWrapper
ERTWrapper \
GTest
#tests

Console.depends = src
Expand Down
33 changes: 33 additions & 0 deletions FieldOpt/GTest/ERTWrapper/test_eclgridreader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <gtest/gtest.h>
#include "eclgridreader.h"

using namespace ERTWrapper;

namespace {

class ECLGridReaderTest : public ::testing::Test {
protected:
ECLGridReaderTest() {
// Set-up work for each test
}

virtual ~ECLGridReaderTest() {
// Clean-up work that does not throw exceptions.
}

virtual void SetUp() {
// Called immediately after the constructor (right before each test)
}

virtual void TearDown() {
// Called immedeately after each test (right before the destructor)
}

// Objects declared here can be used by all tests in this test case.
};

TEST_F(ECLGridReaderTest, TestSomething) {
EXPECT_EQ(0,0);
}

}
12 changes: 12 additions & 0 deletions FieldOpt/GTest/GTest.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include(../defaults.pri)
QT += core
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++11
LIBS += -L../src -lfieldopt
LIBS += -L../ERTWrapper -lertwrapper
LIBS += -lpthread -lgtest -pthread
SOURCES += \
gtest_main.cpp \
ERTWrapper/test_eclgridreader.cpp
68 changes: 68 additions & 0 deletions FieldOpt/GTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Unit Tests

Test are as of sept. 2015 created using the Google Test framework.

Directions for setting up the library on Ubuntu and creating simple tests
may be found at http://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/

## GTest Boilerplate

This boilerplate code is taken from https://code.google.com/p/googletest/wiki/Primer
At this site you can also find some additional documentation on writing tests using the googletest framework.

```
#include "this/package/foo.h"
#include "gtest/gtest.h"
namespace {
// The fixture for testing class Foo.
class FooTest : public ::testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.
FooTest() {
// You can do set-up work for each test here.
}
virtual ~FooTest() {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
}
virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
}
// Objects declared here can be used by all tests in the test case for Foo.
};
// Tests that the Foo::Bar() method does Abc.
TEST_F(FooTest, MethodBarDoesAbc) {
const string input_filepath = "this/package/testdata/myinputfile.dat";
const string output_filepath = "this/package/testdata/myoutputfile.dat";
Foo f;
EXPECT_EQ(0, f.Bar(input_filepath, output_filepath));
}
// Tests that Foo does Xyz.
TEST_F(FooTest, DoesXyz) {
// Exercises the Xyz feature of Foo.
}
} // namespace
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
```
11 changes: 11 additions & 0 deletions FieldOpt/GTest/gtest_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>
#include <gtest/gtest.h>
#include "ERTWrapper/test_eclgridreader.cpp"

using namespace std;

GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
4 changes: 4 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
cd build-FieldOpt-Desktop-Debug/GTest
./GTest
cd ../../

0 comments on commit 6460fd6

Please sign in to comment.