Linked Questions

78 votes
6 answers
17k views

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 ...
Bryan Chen's user avatar
  • 1,145
21 votes
4 answers
3k views

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 = ...
Roger Lipscombe's user avatar
10 votes
3 answers
38k views

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 ...
io-quois's user avatar
  • 111
5 votes
1 answer
6k views

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?
Heisenberg's user avatar
3 votes
4 answers
5k views

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 ...
Julious Igmen's user avatar
2 votes
1 answer
3k views

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 ...
WAQ's user avatar
  • 123
1 vote
1 answer
1k views

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 ...
user avatar
1 vote
2 answers
235 views

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({ ...
faressoft's user avatar
  • 119
0 votes
1 answer
170 views

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 ...
Alessandro Minoccheri's user avatar
0 votes
1 answer
100 views

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 ...
Joyce's user avatar
  • 103
86 votes
11 answers
12k views

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 ...
carlossierra's user avatar
  • 1,425
17 votes
5 answers
20k views

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 ...
t3chb0t's user avatar
  • 2,601
16 votes
4 answers
3k views

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()...
Mihai's user avatar
  • 271
9 votes
4 answers
2k views

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) }...
Wissam Goghrod's user avatar
8 votes
3 answers
2k views

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, ...
John Lippson's user avatar
3 votes
5 answers
2k views

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 ...
adam-beck's user avatar
  • 141
7 votes
3 answers
2k views

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'...
Zalomon's user avatar
  • 1,200
2 votes
3 answers
297 views

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 ...
kibe's user avatar
  • 738
7 votes
2 answers
804 views

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): ...
Jorge Verdeguer Gómez's user avatar
6 votes
2 answers
833 views

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 ...
Karol Selak's user avatar
0 votes
4 answers
6k views

I have a simple class which looks like this: class SpecialList { private List<Integer> varList; SpecialList() { varList = new ArrayList<>(); } void addVar(int i) {...
sbhatla's user avatar
  • 167
0 votes
2 answers
503 views

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(...): ... ...
James Lin's user avatar
  • 199
4 votes
3 answers
352 views

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 ...
Marin Bencevic's user avatar
2 votes
2 answers
183 views

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 ...
53777A's user avatar
  • 1,718
1 vote
2 answers
225 views

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 ...
w0051977's user avatar
  • 7,139
-2 votes
2 answers
354 views

Suppose I have some code as such: function1() { function2() } function2() { function3() } function3() { function4() } function4() { ... } Do I have to write integration tests for ...
Ryn's user avatar
  • 125
0 votes
1 answer
395 views

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 ...
user3002473's user avatar
0 votes
3 answers
630 views

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 ...
Minh Thai's user avatar
  • 141
-1 votes
1 answer
167 views

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 ...
Paul Razvan Berg's user avatar
4 votes
0 answers
177 views

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 ...
obiwanjacobi's user avatar