A question that often arises in development teams is “how do you approach unit-testing for multi-threaded code”? The thing that concerns developers is of course, the order of execution which can be difficult to control when the code is particularly complex. However, while ignoring testing can seem tempting – it’s important to test all of your code. Here are some ideas on how to approach it: Force the code to execute in a synchronous manner Given that a unit-test has the most value when it can be reproduced and executed again and again, multi-threaded code presents real challenges. We’ve found that one method that can help is forcing asynchronous code to be executed synchronously. The method involves taking the core logic and then reassigning it to a separate class. The content which is not synchronous is executed by the core logic. You should be able to map the path of the calls made by the core logic – and thus produce repeatable unit-tests. However, at Typemock we have a preferable
Unit-testing for multi-threaded code – how should this be approached?
20 сентября 202020 сен 2020
2
1 мин