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

Added Unit Test for Republisher Node on Noetic Branch #39

Open
wants to merge 5 commits into
base: noetic-devel
Choose a base branch
from

Conversation

IrinaTerebiznik
Copy link
Contributor

@IrinaTerebiznik IrinaTerebiznik commented Dec 23, 2024

This repository contains a unit test for a ROS node that republishes messages from /input_topic to /output_topic. The test ensures the republisher node processes and republishes messages correctly.
Note that this test is non-automated and must be run manually, as explained in the README in the test/UnitTests folder.

@IrinaTerebiznik IrinaTerebiznik changed the title Add Unit Test for Republisher Node on Noetic branch Added Non-Automated Unit Test for Republisher Node on Noetic Branch Dec 23, 2024
@IrinaTerebiznik IrinaTerebiznik changed the title Added Non-Automated Unit Test for Republisher Node on Noetic Branch Added Unit Test for Republisher Node on Noetic Branch Dec 23, 2024
Copy link
Member

@leandropineda leandropineda left a comment

Choose a reason for hiding this comment

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

Reviewed! The test looks good, I added a few questions and change requests.

Also, please rename the UnitTests folder to use lowecase and underscores, as we adhere to PEP8 style guide: https://peps.python.org/pep-0008/#package-and-module-names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

@@ -1 +1,6 @@
__pycache__/
/inorbit_republisher/test/sample_data/build/
Copy link
Member

Choose a reason for hiding this comment

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

These ignores shouldn't be needed if running on a docker container

@@ -54,6 +54,16 @@ republishers:
topic: "/inorbit/custom_data/0"
key: "navsat"

# Añadido para los tópicos input y output
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid using language other than english

@@ -54,6 +54,16 @@ republishers:
topic: "/inorbit/custom_data/0"
key: "navsat"

# Añadido para los tópicos input y output
- topic: "/input_topic"
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't use this file for testing purposes, as it's the example used on the main README. Instead, I'd create a separate configuration file e.g. unittest_config.yaml under the test folder, and only include this section.

1. **Build the Workspace**:
Ensure the workspace is built and the environment is sourced:
```bash
cd ~/catkin_ws
Copy link
Member

Choose a reason for hiding this comment

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

Please add instructions for running tests on a docker container (see package README). This seems to run on a host machine

2. **Source and Run the Workspace**:
```bash
. ~/catkin_ws/devel/setup.bash
rostest inorbit_republisher test_republisher.test
Copy link
Member

Choose a reason for hiding this comment

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

Nit: fix indentation

self.test_pub = rospy.Publisher('/input_topic', String, queue_size=10)
self.received_messages = []
rospy.Subscriber('/output_topic', String, self.callback)
rospy.sleep(1)
Copy link
Member

Choose a reason for hiding this comment

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

Do you need a sleep here? Why?
Note that sleeps or wait times on unittests are typically a smell and are discouraged.

expected_message = f"input_to_output={test_message}"
rospy.loginfo(f"Publishing: {test_message} to /input_topic")
self.test_pub.publish(String(data=test_message))
rospy.sleep(1)
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried rospy.wait_for_message instead of the sleep?

rospy.loginfo(f"Messages received: {self.received_messages}")
self.assertIn(expected_message, self.received_messages)

def test_no_message(self):
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the value of this test. self.received_messages is initialized as an empty list on the setUp, so it will always have len == 0.

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.

2 participants