Best Practices for Testing C++ WebAssembly in the Browser

0
8
Asked By PixelPenguin75 On

I'm currently developing a project called Img2Num, which turns images into color-by-number templates. It relies on C++ compiled to WebAssembly using Emscripten for demanding image processing tasks, including Fast Fourier Transforms, Gaussian blurs, and K-Means segmentation. However, I'm facing challenges with unit testing. I've identified two main testing strategies: testing in JavaScript with tools like Vitest, which doesn't really check the C++ logic, and testing in C++ with Google Test, which runs locally but not in a browser/WebAssembly environment. Unfortunately, neither approach fully addresses my needs. Testing in JavaScript is a turn-off for potential C++ contributors, since they have to use a language they might not know, while testing solely in C++ doesn't ensure the behavior is correct once compiled to WASM. I'm looking for an effective solution that allows for unit testing in C++, within a browser-like environment, and is friendly to C++ developers. Any insights, examples, or workflows would be greatly appreciated!

2 Answers

Answered By JavaScriptJuggler On

Why not separate your tests? You could have distinct sets for the C++ logic and JavaScript image validation. It could streamline your workflow since changes in one area won't necessarily affect the other, allowing you to focus on each part individually while still maintaining overall functionality.

Img2NumDev -

That’s a good point, but how do I manage cases where I need to call tests from both contexts? For instance, when Gaussian blur is involved in preprocessing across both C++ and JS.

Answered By CodeCrafter42 On

Have you thought about writing C++ unit tests that can run directly in the browser after being compiled with Emscripten? It might be easier than you think, especially since there are existing test frameworks that support this. They can help you create a setup that meets your project’s specific needs, allowing for better testing coverage.

Img2NumDev -

That sounds promising! Can you suggest any specific frameworks or tools that would help me integrate this kind of testing?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.