Linked Questions
30 questions linked to/from How should I test the functionality of a function that uses other functions in it?
78 votes
6 answers
17k views
Do I need unit test if I already have integration test?
If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write ...
21 votes
4 answers
3k views
How to structure tests where one test is another test's setup?
I'm integration testing a system, by using only the public APIs. I have a test that looks something like this: def testAllTheThings(): email = create_random_email() password = ...
10 votes
3 answers
38k views
Unit testing functions calling other tested functions [duplicate]
I have three functions: ValidateUsername(), which determines if a string is a valid username according to some rules SetUsername() which sets a string as a user's Username if it passes validation ...
5 votes
1 answer
6k views
Java Unit testing multiple test cases in one test [duplicate]
Is it good practice to have multiple test cases in one test or should I always create one test for single test case in every situation even if it is redundant? Why?
3 votes
4 answers
5k views
Implementing TDD for existing code [duplicate]
I've just been learning Unit Testing and I'm trying to understand how I could incorporate it with a project with existing code. Say I wanted to write tests for a specific class in that project, but ...
2 votes
1 answer
3k views
How to unit test public method which internally calls many internal or private methods which are already individually unit tested [duplicate]
In our ASP.NET Core application, we have many APIs which are calling public method from the service class. Service class is implementing an Interface. Each service method (depending upon complexity ...
1 vote
1 answer
1k views
Focus of unit tests on code [duplicate]
I discover mocking strategies after 50% of tests was writen, and I'm confused about how much focus unit tests should have, for example on class method. I know that for external dependencies you should ...
1 vote
2 answers
235 views
How to write unit tests a method with a result that is highly based on another method [duplicate]
How to write unit tests a method with a result that is highly based on another method ? async function getStatus( session, correlationId, data ) { const client = new SomeAPIWrapperClient({ ...
0 votes
1 answer
170 views
Test logic with external data [duplicate]
I have a site programmed in PHP where I make more call to external server that return me big xml of data. For each record of the xml I have to make other external call to get other data. So my ...
0 votes
1 answer
100 views
Do we do white box testing on methods or on an overall program? [duplicate]
I am very confused about white box testing. A simplified version of the example: the entire system consists of three methods - methodA(), methodB(), methodC(). The program starts from methodA(), and ...
86 votes
11 answers
12k views
Shouldn't unit tests use my own methods?
Today I was watching a "JUnit basics" video and the author said that when testing a given method in your program, you shouldn't use other of your own methods in the process. To be more specific, he ...
17 votes
5 answers
20k views
How to make one test depend on the results of another test?
Let's say there is a utility class that provides some common static methods used everywhere in your code by many other classes. How would you design your unit tests for the consumers of the utility ...
16 votes
4 answers
3k views
Is there any value in writing a unit test that is a subset of another test?
To give a slightly contrived example, let's say I want to test that a function returns two numbers, and that the first one is smaller than the second one: def test_length(): result = my_function()...
9 votes
4 answers
2k views
Should I test a method that calls a method that is already tested?
I have a method that does something like this public void addFunds(Account account, int price) { int credits = account.getCredits() account.setCredits(credits + price) saveOrUpdate(account) }...
8 votes
3 answers
2k views
Philosophy on unit testing daisy-chained methods?
Problem Statement: I have a class that does some validation and it looks something like this: func a() {b()} func b() {c()} func c() {d()} func d() {e()} func e() {return} This is a simplified view, ...
3 votes
5 answers
2k views
How do you unit test a function that clears properties?
I have a very common function that I have always unit tested in the same way, but I'm wondering if there is a better solution or if it's even possible a code smell is involved. It seems like a very ...
7 votes
3 answers
2k views
Should unit tests always overlap
This is a test design question. I have a class 'handler' that accepts a 'validator' that checks some business logic on what's passed to the handler. I made the unit tests for the validator and now I'...
2 votes
3 answers
297 views
Given a function that has already been unit tested, but is present in another unit, should I bother testing it again?
Say, for instance, I have this simple function in my domain layer: function canCreateNewUsers (principal: User): boolean { return principal.isSuperAdmin || principal.isAdmin // || ... a bunch of ...
7 votes
2 answers
804 views
How do you unit test functions split in smaller functions
The problem is the following, suppose we have this functions: from PIL import Image from magiclibrary import perform_some_operation, stack_images def load_image(path: str): if isfile(path): ...
6 votes
2 answers
833 views
What is the best practice of testing methods which call each other?
Say I have a method A which calls a method B and does one additional thing. The B method behaves differently in 10 different cases and I have a broad unit test describing it. And now I want to test my ...
0 votes
4 answers
6k views
How do I test a method which requires another method of the same class to be invoked first?
I have a simple class which looks like this: class SpecialList { private List<Integer> varList; SpecialList() { varList = new ArrayList<>(); } void addVar(int i) {...
0 votes
2 answers
503 views
What is a good unit testing strategy against a chain of public method calls?
say I have this code which is a chain of public methods, public_c calls public_b calls public_a def public_a(...): ... def public_b(...): ... public_a(...) def public_c(...): ... ...
4 votes
3 answers
352 views
How narrow should my unit tests be?
Here's an example: I have a chat module in my app, and there's a ChatService class that is responsible for networking, and there's a ChatNotificationService helper class that is responsible for ...
2 votes
2 answers
183 views
Should I write duplicated tests for 'setDate' and 'isValidDate' methods?
Let's say I have a method called setDate. I also have another method called isValidDate to see if a string is a valid date string. For convenience, setDate uses isValidDate internally as a mean of ...
1 vote
2 answers
225 views
One method per unit test?
Say I have a Service Layer method like this: public void TestMethod() { DomainObject domainObject = new DomainObject(); domainObject.TestMethod(); } TestMethod looks like this in the Domain ...
-2 votes
2 answers
354 views
Should you write integration tests at every level?
Suppose I have some code as such: function1() { function2() } function2() { function3() } function3() { function4() } function4() { ... } Do I have to write integration tests for ...
0 votes
1 answer
395 views
Bad idea to use the same test cases for multiple parts of a contiguous algorithm?
I'm working on an algorithm that's split up into multiple parts, each of which performs different tasks but is more or less separate from the others, by which I mean the only interaction between the ...
0 votes
3 answers
630 views
Unit Testing method with multiple steps
I have a validation method like this def validate(a, b, c, d, e, f): Boolean = { val rs1 = check1(a, b) val rs2 = check2(c, d) val rs3 = check3(e, f) rs1 && rs2 && rs3 } I ...
-1 votes
1 answer
167 views
Best practices on unit tests for consecutive functions
Let's say we have function A and function B which perform consecutive operations on some data, with B never receiving the data before A processes it. Function A makes exhaustive checks on potential ...
4 votes
0 answers
177 views
How to manage success dependency between unit tests [duplicate]
How do you manage the dependency of one unit test on another unit test succeeding? So, supposed I have a class and this class has say 5 methods. I create like 2 dozen unit tests (test methods) for ...