TESTING 3D GEOMETRY ALGORITHMS IN OCCT

Short introduction to recent improvements in code quality

Apr 12, 2024
by Matas Ubarevicius

We've been working on improving the quality of our core codebase by adding new unit tests and restructuring the code in the @bitbybit-dev/occt layer. In this article, we'll explain why these changes were necessary and how they benefit our platform's users.

The image showing a girl coding geometry in the room full of 3D printed objects

Looking for the best way to test 3D geometry algorithms

What is @bitbybit-dev/occt?

@bitbybit-dev/occt is the core CAD layer of our platform shared with the open-source community under the MIT license. This layer is built on top of the OCCT 3D Technology kernel through the OpenCascade.js library. Numerous 3D geometry algorithms have been developed, enabling our users to create intricate 3D designs. As the codebase grew steadily, it became necessary to split it into smaller modules. However, before this could be done, it was imperative to write unit tests to ensure that the refactoring would not disrupt the existing functionality.

Our Approach to Unit Tests

Unit tests are small pieces of code designed to test specific parts of an algorithm. While pure unit tests typically mock all third-party code and focus solely on small functions, we initially opted to write broader tests that also encompass the full geometry kernel. This pragmatic decision ensures that any potential degradations are identified when integrating new versions of OCCT. This decision does not mean that more focused unit tests will not be written in the future where they are more beneficial.

In this context, our Unit Tests may be viewed as End-to-End tests. While purists may raise concerns, in our current situation, it proves highly beneficial. Testing geometry-based algorithms loses significance if the constructed geometry cannot be effectively validated. Running the complete geometry kernel against the unit tests simplifies testing and enhances its utility.

Though a substantial number of unit tests were already in place, they did not cover all endpoints. Refactoring the codebase without comprehensive test coverage would have been risky. Therefore, it was logical to prioritize writing the missing unit tests before proceeding with the refactoring.

Sharing Unit Test Coverage Report

While our approach to testing is practical, we also prioritize transparency. Hence, we've decided to share the coverage report with the public. This report provides insights into the current state of the unit tests and the extent of code coverage.

Access the report here:

Although we have not yet achieved 100% coverage, we're steadily progressing towards that. Reaching 100% coverage is indeed a significant milestone, but it's important to acknowledge that the journey of unit testing doesn't stop there. It's an ongoing process of refining and expanding test coverage to ensure the highest possible quality of the codebase to its users. While we continue to progress towards that goal, it reflects our unwavering dedication to maintaining the integrity and reliability of our codebase, demonstrating our commitment to providing a robust platform experience for our users.

Refactoring

Maintaining a tidy codebase is essential, but over-architecting solutions without assessing the codebase's growth and adoption can be impractical. Over the past few months, numerous new features have been added to this particular section of the codebase, making it increasingly challenging to navigate. This served as a clear indication that restructuring the code into smaller modules was necessary, and that's precisely what we've done.

While algorithms remain unchanged, the code has been restructured to enhance readability and facilitate future feature additions. Additionally, it simplifies the process of writing new unit tests and maintaining existing ones.

We anticipate that this restructuring will reduce the occurrence of bugs in our platform and facilitate community contributions to the codebase.

What's next?

OCCT provides an exceptional geometry kernel, and we have plans to implement numerous new 3D algorithms within this open-source layer. Establishing a more robust foundation is crucial for further development.

While OCCT serves as the foundation, we also have higher-level algorithms that warrant thorough testing. We will continue to write unit tests for @bitbybit-dev/core and @bitbybit-dev/occt-worker repositories, and we'll share the coverage reports with the public in due course. You will be able to find these reports on our dedicated site:

While unit tests are vital for ensuring codebase quality, we have plans to implement additional quality assurance measures in the future. Stay tuned for further updates.

Our objective is to ensure the stability of the codebase and instill trust in the algorithms we've developed among the computational designers and developers who utilize our platform worldwide.