Answer the question
In order to leave comments, you need to log in
How to test code that has a dependency on external functions and libraries?
The task is to write a unit test and cover as much as possible the internal library that the previous programmers wrote. This library is tied to other external libraries.
Almost every function has a dependency on private or external functions...and the goal is to cover almost 90% of the code.
I use Jasmine, Karma, Istanbul.
If I start making mock or spy functions, either the test does not cover that line, or a closure occurs and the function closes that value and the mock is ignored .... (
I would be grateful for comments and ideas who had experience in writing code for their internal libraries.
function internalFoo1(input) {
var result = internalFoo2(input*2);
var finalResult = externalLibraryBar1(result);
return result;
};
function internalFoo2(value) {
var operation = externalLibraryBar2(value*2);
var response = externalLibraryBar3(operation);
return response;
}
Answer the question
In order to leave comments, you need to log in
I think the developers see your question and think "Not all code can and should be tested." I'll dig a little deeper. I recommend thinking about the benefits first. What is the value of high coverage in CI?
If you want high coverage to improve system stability, then you need to accept the fact that in the current implementation the code is untestable and you need to refactor it, getting rid of implicit dependencies and breaking it into atomic modules. Realistically assess the timing of such an event and rethink about the benefits.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question