Questions tagged [unit-testing]

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

Filter by
Sorted by
Tagged with
36
votes
5answers
4k views

Is the usage of random values in unit testing a good practice?

Having worked in complex solutions that had Unit Tests and Integration Test in the CI/CD pipeline, I recall having a tough time with tests that failed randomly (either due to random values being ...
0
votes
1answer
56 views

Additional modules in unit tests

We have capital-U Unit Tests that are supposed to be testing a particular slice of our code. This code has a dependency on an IConverter<TIn, TOut> (a wrapper similar to AutoMapper). The ...
-1
votes
3answers
180 views

Dilemma over authenticity of gcov generated code coverage percentage where unit tests are not technically correct

When I joined my company as a new comer and I was exploring the unit test suite of the product code. It is using gtest framework. But when I checked all the tests, they were testing the whole ...
0
votes
1answer
94 views

How to write tests in TDD for downloading and unpacking a file?

So I want to write this function that downloads a file and unpacks it in python using TDD. The function will look like this approximately import urllib.request import tarfile def download_and_unpack(...
0
votes
1answer
76 views

Best practices for seperating/designing classes and methods for use in testing

I run unit and integration tests on my system. These create, start, stop and delete Docker containers. I want the exact same state in my Docker environment at the end of the tests as I had at the ...
1
vote
2answers
79 views

Best Practice: Unit test coverage vs. in-method sanity checks [duplicate]

I have a code-coverage requirement of of a certain percentage, and face the following tradeoff: Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability? Lets ...
1
vote
0answers
38 views

Integration Testing Stripe Payments - stripe-mock or Stripe's test mode?

I'm building an automated test suite to integration/feature test my organization's Stripe implementation within a GitLab CI pipeline. We're running Laravel 8 and using phpunit for testing. Within this ...
-3
votes
1answer
79 views

Shall QA team share their Test Cases with Dev Team? [duplicate]

I am building the test process for my development team. Currently, we have multiple ping-pong scenarios between Dev and Test teams. to send the product to QA then QA find issues and return them to ...
0
votes
1answer
217 views

What's an edge case in email validation, and algorithms?

An edge case is usually defined as what Wikipedia would say, An edge case is a problem or situation that occurs only at an extreme (maximum or minimum) operating parameter. For example, a stereo ...
-3
votes
1answer
47 views

What are the downsides to containerizing Mongo DB for unit testing? [closed]

Let me give a little bit of background for this question. For the record, this is a question about architecture and software engineering practice and not about the specific technologies that I am ...
0
votes
2answers
64 views

Mock part of a static method

I am designing a test for an existing static method: public static boolean hasPermissions(String username, int pageid) { PermissionsService s = new PermissionsService(); int[] pages = s....
3
votes
3answers
288 views

Should unit tests assert the inputs to dependencies?

tl;dr: Is it a unit test or an integration test, to ensure that the inputs to a mocked dependency were correct? More details: Suppose I'm given a requirement like this: Create a function that returns ...
-3
votes
1answer
53 views

Testable pattern for bytecode interpreter

I am developing virtual machine for prototype-oriented language. And i found one problem. I dont know how to write interpreter that can be tested using unit tests - naive implementation of interpret ...
-3
votes
2answers
164 views

Is inversion of control the opposite of “tell, don't ask” principle?

First, let me explain what I mean by inversion of control and tell, don't ask in this context. I have 4 classes MailController, UserData, Subscription and MailService. MailController is a consumer of ...
1
vote
3answers
112 views

Clarifying the steps in a CI/CD, but namely if if unit testing should be done building a Docker image or before

I'm building at a Build and Deployment pipeline and looking for clarification on a couple points. In addition, I'm trying to implement Trunk Based Development with short-lived branches. The process I ...
0
votes
0answers
66 views

Idiomatic Golang Unit Testing

Currently I have some code which is structured like this: type Service struct { // some dependencies } func (s *Service) FindStuff(ctx Context) { // this signature cannot be changed // some ...
0
votes
2answers
112 views

Is there any benefit testing only with mocks/fakes/doubles?

Say I want to test the behavior of the GUI while I follow a PassiveView approach. I also use the command pattern to handle the actions of the user. So given a PersonView and a PersonService with a ...
-1
votes
2answers
172 views

How do you unit test methods with hard/impossible inputs to hardcode?

I have the following problem. I have a method which takes two other custom objects to work. This objects are required by the method because they have the information that the method requires to ...
3
votes
2answers
136 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): ...
2
votes
3answers
172 views

Extending the class to test it: is this testing approach fine?

I am curious if the following example of testing a class with protected methods is fine. For example, say you have the following class Foo that has method a() of return type Bar: class Foo { ...
-1
votes
4answers
139 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) {...
2
votes
1answer
62 views

Choosing test method of bash command output with bats

Context While writing a bash script I would like to test every command I write. To do so I create a separate function per command that executes the function. In addition I want to log the output of ...
-1
votes
1answer
45 views

Unit testing a chain of network requests - how many tests?

I have some fairly complex code, that is a chain of API calls. The result of one call is the input of the next. class PaymentService { func pay(userId: String) async { let paymentSource = ...
18
votes
3answers
2k views

How do you push Design changes in TDD in late development stage

I was recently part of a TDD development team. At certain point I realized that there is a design mistake instead of Object Oriented Design and Structural design the problems were solved via statuses. ...
6
votes
3answers
363 views

Is there a logical complexity beyond which TDD doesn't work?

All the books which talk about test-driven development (TDD) illustrate it with only very basic examples, less than 100 LOC. The algorithms I wrote using TDD were larger, but still relatively small in ...
13
votes
3answers
2k views

How would you test a lexer?

I'm wondering how to effectively test a lexer (tokenizer). The number of combinations of tokens in a source file can be huge, and the only way I've found is to make a batch of representative source ...
0
votes
3answers
172 views

How to model and unit test code with multiple side effects?

How to unit test code that requires multiple side effects? For example, making an invoice. Simple action requires few thing to happen simultaneously: create invoice in db send invoice to backend ...
1
vote
1answer
95 views

C# - Menu Implementation - Help writing it in a testable way

The Question: I'm developing an app in C# and am currently designing a menu which contains submenus and needs to be different depending on the category of the user. I've written the code but am ...
4
votes
7answers
411 views

Negative unit testing

Let's say I have a class like this: public class Validator { private HashSet<byte> _validFlags; public Validator() { _validFlags = new HashSet<byte&...
6
votes
1answer
461 views

Why Golang projects seldom use mocking library in testing?

New to golang and is now researching on how to do test in golang. I see that there are popular mocking library like gomock. However, at the same time, I see that large golang open source projects don'...
0
votes
1answer
97 views

How to Unit test / design differently a complicated free function

I have written a Command Line Interface, where the user has to construct an object basically by providing input to a bunch of questions. I have a hard time testing these functions as there is too much ...
0
votes
2answers
125 views

How to write the test for a class function which depends on another function to be tested in TDD approach?

I have a class class A { List<int> a; A() { this.a = []; } void add(int x) { a.append(x) } List<int> display() { return a; } } This is a simple class I want to ...
3
votes
2answers
460 views

Unit testing a generic method not caring about the generic type

I have the following code public class MyCollection<T> { public void Add(T obj) { ... } public int Count { get; } } and the following unit test to check whether Add increases the Count ...
0
votes
0answers
38 views

Using a bulletin board to support Separation Of Concerns

Context: I'm working on an embedded system with many small functional modules. The business logic within each module is made as simple as possible, but those modules generally need to gather bits of ...
-5
votes
3answers
241 views

How to unit test a public method that calls a private method [duplicate]

Here is a very basic example to illustrate my point class SomeClass { publicMethod1(param1, param2) { if (param1 === "some value") { // do stuff } else { ...
0
votes
2answers
190 views

What if integration testing makes more sense than unit testing for a certain method?

I don't want to spam you with a ton of code, but please have a quick look at this boiler-plate method: In this scenario let's say I have a ProcessingText.py file (class) that I finished its unit ...
-2
votes
3answers
125 views

Can TDD and White-box testing be combined directly?

I am getting started with software testing in Java and was wondering if test-driven dev and white-box testing could be combined directly... If not, what ways can we extend TDD to combine white box ...
-2
votes
2answers
241 views

Where to put data generating functions for unit tests

I am writing a unit-test framework (for Matlab/Octave, but that does not matter) which also supports property based testing. Thus, I need some functions which generate random data which are tailored ...
0
votes
2answers
58 views

How to cover by tests HTTP API wrapping library

As mentioned in title, I don't understand how I supposed to cover by tests code which is just wrap http api. I guess I can write only unit tests, because wrapped service is paid. Integration tests in ...
1
vote
2answers
127 views

Is there a pattern for unit/integration testing where tests that are higher level are intended to act as “gates” for other more specific tests?

The motivating concept here is that the fewer tests you have, the faster your test suite runs. This kinda feels like I'm basically describing smoke tests, but I think smoke tests and other tests are ...
0
votes
2answers
44 views

Logic in data provider vs test body

Lets say we have a class Cat: class Cat{ public eat(String food){ if (food.contains("cat")){ burp(); } } private burp(){ System.out.println(&...
0
votes
1answer
60 views

Properly testing UI presenters without duplicating tests of subcomponents

I am writing the embedded firmware for an effect pedal. The pedal's ui consists of a few knobs a few buttons and a few leds and it consists of various control modes each corresponding to a seperate ...
-6
votes
1answer
119 views

Why is automatically generating automated tests frowned upon?

First, the most obvious grouse someone has against this I can think of is the intricacies of an actual method. It's not enough to merely ensure no errors are thrown. Functions usually contain ...
2
votes
2answers
136 views

Providing same API implemented in multiple languages

Our budding (currently internal) API deals with building information models, originates in our main application written in c++. There is a small implementation of it in C# for easy interop with other ...
8
votes
5answers
1k views

What would be a better approach to write methods which returns several different string outputs?

I have some code similar to shared below, which returns different kinds of response messages to the caller. If the return value is empty string, the process is continued. If a message is returned it ...
0
votes
3answers
185 views

How to write unit tests for REST API that are atomic?

I am writing a REST API for use by the front-end web and mobile frameworks. Naturally, I write unit tests for each endpoint, which makes developing, evolving, and maintaining the API easier. However, ...
-1
votes
1answer
236 views

Java: Splitting a large unit test class

The project (Java/Spring) I currently work on has a rather large unit-test class for one of its services : more than 1000 lines, several Nested class (one per big functionality), some tests without a ...
0
votes
2answers
98 views

Unit testing multiple features in one test

I'm writing a small utility class to create an abstraction for addEventListener (JavaScript/DOM) Let's say I have to test for these features: Single event target with a single event Multiple events ...
4
votes
2answers
246 views

Doesn't “Always test through the public interface” contradict testing of individual composed functions?

I'm currently reading "Composing Software" by Eric Elliott, which is about functional programming in JavaScript. He states that if you compose multiple functions together, and that these ...
-1
votes
3answers
168 views

Should methods with business logic be made private? [duplicate]

So I am writing a project using Spring Boot. All of my logic resides in @Service classes. I have separated each service class based on entity. For example - If I have two independent entities A and B, ...

1
2 3 4 5
33