Commit de54891f authored by VoVAllen's avatar VoVAllen Committed by Chao Ma
Browse files

[Test] Add gtest to project (#547)

* add gtest module

* add gtest

* fix

* Update CMakeLists.txt

* Update README.md
parent 86d60a1f
...@@ -4,3 +4,6 @@ ...@@ -4,3 +4,6 @@
[submodule "third_party/dlpack"] [submodule "third_party/dlpack"]
path = third_party/dlpack path = third_party/dlpack
url = https://github.com/dmlc/dlpack.git url = https://github.com/dmlc/dlpack.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
...@@ -68,3 +68,16 @@ target_link_libraries(dgl ${DGL_LINKER_LIBS} ${DGL_RUNTIME_LINKER_LIBS}) ...@@ -68,3 +68,16 @@ target_link_libraries(dgl ${DGL_LINKER_LIBS} ${DGL_RUNTIME_LINKER_LIBS})
# Installation rules # Installation rules
install(TARGETS dgl DESTINATION lib${LIB_SUFFIX}) install(TARGETS dgl DESTINATION lib${LIB_SUFFIX})
# Testing
if(BUILD_CPP_TEST)
message("Build with unittest")
add_subdirectory(./third_party/googletest)
enable_testing()
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
file(GLOB_RECURSE TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/tests/cpp/*.cc)
add_executable(runUnitTests ${TEST_SRC_FILES})
target_link_libraries(runUnitTests gtest gtest_main)
target_link_libraries(runUnitTests dgl)
add_test(UnitTests runUnitTests)
endif(BUILD_CPP_TEST)
Unit test Unit test
=== ===
## Python Unittest
The code organization goes as follows: The code organization goes as follows:
* `backend`: Additional unified tensor interface for supported frameworks. * `backend`: Additional unified tensor interface for supported frameworks.
...@@ -15,3 +16,14 @@ The code organization goes as follows: ...@@ -15,3 +16,14 @@ The code organization goes as follows:
functions). functions).
* `lint`: Pylint-related files. * `lint`: Pylint-related files.
* `scripts`: Automated test scripts for CI. * `scripts`: Automated test scripts for CI.
## C++ Unittest
Compile with unittest by executing the command below
```
# Assume current directory is the root directory of dgl, and googletest submodule is initialized
mkdir build
cd build
cmake .. -DBUILD_CPP_TEST=1
make -j${nproc}
./runUnitTests
```
#include <gtest/gtest.h>
#include <dgl/graph.h>
TEST(GraphTest, TestNumVertices){
dgl::Graph g(false);
g.AddVertices(10);
ASSERT_EQ(g.NumVertices(), 10);
};
Subproject commit f71fb4f9a912ec945401cc49a287a759b6131026
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment