Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rostest example #71

Merged
merged 13 commits into from
Feb 11, 2017
Merged

Rostest example #71

merged 13 commits into from
Feb 11, 2017

Conversation

ValRat
Copy link
Collaborator

@ValRat ValRat commented Jan 26, 2017

Closes #66, closes #67

@ValRat
Copy link
Collaborator Author

ValRat commented Jan 26, 2017

Basics have been written, need to change some CMakeList entries:
instead of catkin_add_gtest(), do add_rostest_gtest() since the former runs the node external of the ros computational network (which isn't what you want to do when doing integrated testing)
Reference

Still need to add a blurb about where results are located.

@@ -108,11 +109,19 @@ some_ros_package
| | <b>my_node.cpp</b>
</pre>

## Launch files
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 can't believe I didn't put a section on this in the readme..... good idea! 😃

@garethellis0
Copy link
Collaborator

Also, in the example given in sample_package, I'd just be able to launch it, point it at some gtest tests, and it'd run roscore, allowing me to run my node and test methods directly, rather then testing the external publish/subscribe interface?

@ValRat
Copy link
Collaborator Author

ValRat commented Jan 30, 2017

In response to above (for documentation of discussion sake):
With rostest you'd be able to launch the node and test the publish/subscribe interface. Testing member methods should be done at the gtest unit test levels.

Copy link
Collaborator

@garethellis0 garethellis0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a full review, just happened to spot these while I was using your PR as reference for how to use setup / test fixtures

}
};

TEST_F(MyClassTest, MyNodeTest){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that perhaps we should name the test class MyNodeTest, with the second name being reserved to indicate very briefly the functionality you're trying to test.


/**
* This is the helper class which will publish and subscribe messages which will test the node being instantiated
* It contains on the minimum:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"at the minimum" might be a better way of phrasing it

README.md Outdated
@@ -94,7 +95,8 @@ some_ros_package
| | <b>MyNode.h</b>
|
└───test
| | <b>my-node-test.cpp</b>
| | <b>my_node_test.cpp</b>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we've decided to only change the naming convention to use underscores for ros-tests, this should still be my-node-test.cpp

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, my_node_rostest.cpp should be in this hierarchy

README.md Outdated
## Testing
- GTest is our primary testing tool at the moment. The ROS wiki has a quick intro to it [here](http://wiki.ros.org/gtest), and we also strongly recommend you read Google's introduction to it [here] (https://github.com/google/googletest/blob/master/googletest/docs/Primer.md), then setup and write a few example tests before you start using it with ROS.
- Once you've setup your tests in ROS, run `catkin_make run_tests` to run them
- To run the tests for a specific package, run `catkin_make run_tests_MY_PACKAGE_NAME`

### Rostest
- For tests which require more than one active node, i.e. integrated testing, the rostest framework provides a way to launch your test alongside all the nodes it requires. This is an extension on roslaunch enabling it to run test nodes. Special test nodes are nested within a `<test></test>` tag. This also needs a special entry under CMakelists as shown in the sample package. See more details [here](http://wiki.ros.org/rostest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is an extension..." has an extra space


// spinOnce allows ros to actually process your callbacks
// for the curious:
// http://answers.ros.org/question/11887/significance-of-rosspinonce/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky thing, but lines 60 & 61 can be one line

messageOutput = msg->data.c_str();
}

std::string getMessage(){
Copy link
Collaborator

@garethellis0 garethellis0 Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this function. I believe test fixtures have access to protected variables. Might just be cleaner to make it a direct access. (that being said, that's kind of icky) or just making the messageOutput private.

ros::NodeHandle nh_;
std::string messageOutput;
ros::Publisher testPublisher;
ros::Subscriber testSubscriber;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost last thing - promise. Variables should be written_like_this

}
};

TEST_F(MyNodeTest, ExclamationMarkAppend){
Copy link
Collaborator

@garethellis0 garethellis0 Feb 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just going off how tests have been named so far, this should be exclamationMarkAppendTest

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about it some more, that convention is pretty stupid. There's really no reason to have the word "test" on the end of each test, so exclamationMarkAppend would be fine (note changes to capitalization)

@garethellis0
Copy link
Collaborator

I keep coming back to approve it and seeing stuff... sorry... 😆

@garethellis0
Copy link
Collaborator

What could possibly go wrong?

@garethellis0 garethellis0 merged commit 451f557 into master Feb 11, 2017
@ValRat ValRat deleted the rostest_example branch August 13, 2017 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rostest to sample package Add rostest testing procedure to readme
2 participants