Skip to main content

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
0 votes
1 answer
76 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 ...
Bryan Boettcher's user avatar
-1 votes
3 answers
562 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 ...
user1228352's user avatar
1 vote
1 answer
341 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(...
Martin Raspaud's user avatar
0 votes
1 answer
90 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 ...
slashleo's user avatar
1 vote
2 answers
301 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 ...
MPIchael's user avatar
  • 269
3 votes
2 answers
920 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 ...
Oliver Lewis's user avatar
-3 votes
1 answer
729 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 ...
asmgx's user avatar
  • 97
1 vote
1 answer
983 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 ...
cpx's user avatar
  • 379
1 vote
2 answers
395 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....
Zort's user avatar
  • 31
5 votes
3 answers
1k 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 ...
George T's user avatar
  • 295
-3 votes
2 answers
541 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 ...
I Want Answers's user avatar
1 vote
3 answers
2k 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 ...
cheslijones's user avatar
0 votes
2 answers
220 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 ...
George Z.'s user avatar
  • 705
-1 votes
2 answers
836 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 ...
Jorge Verdeguer Gómez's user avatar
7 votes
2 answers
683 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): ...
Jorge Verdeguer Gómez's user avatar
5 votes
4 answers
5k 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 { ...
oneturkmen's user avatar
0 votes
4 answers
5k 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) {...
sbhatla's user avatar
  • 167
2 votes
1 answer
200 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 ...
a.t.'s user avatar
  • 225
-1 votes
1 answer
76 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 = ...
Lord Zsolt's user avatar
19 votes
3 answers
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. ...
Alexander Petrov's user avatar
7 votes
3 answers
507 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 ...
Arseni Mourzenko's user avatar
15 votes
3 answers
3k 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 ...
SuperJMN's user avatar
  • 453
1 vote
3 answers
721 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 ...
daneejela's user avatar
  • 201
1 vote
1 answer
319 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 ...
Nick's user avatar
  • 149
5 votes
7 answers
855 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&...
Vladimir Stokic's user avatar
11 votes
1 answer
3k 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'...
cytsunny's user avatar
  • 637
0 votes
1 answer
555 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 ...
Leon0402's user avatar
0 votes
2 answers
2k 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 ...
rahul  Kushwaha's user avatar
4 votes
2 answers
2k 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 ...
user avatar
0 votes
0 answers
42 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 ...
fearless_fool's user avatar
-4 votes
3 answers
10k 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 { ...
Jacob's user avatar
  • 95
0 votes
2 answers
444 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 ...
Ahmed Alhallag's user avatar
-2 votes
3 answers
688 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 ...
tavalendo's user avatar
  • 115
-2 votes
2 answers
433 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 ...
tommsch's user avatar
  • 115
0 votes
2 answers
97 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 ...
Eduard Romanyuk's user avatar
1 vote
2 answers
234 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 ...
Steven Lu's user avatar
  • 519
0 votes
2 answers
95 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(&...
Anmol Singh Jaggi's user avatar
-1 votes
1 answer
67 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 ...
Liarokapis Alexandros's user avatar
-6 votes
1 answer
173 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 ...
I Want Answers's user avatar
2 votes
2 answers
490 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 ...
Balinth's user avatar
  • 129
8 votes
5 answers
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 ...
Tau's user avatar
  • 191
0 votes
3 answers
466 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, ...
arslancharyev31's user avatar
0 votes
1 answer
1k 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 ...
Baerrow's user avatar
  • 125
0 votes
2 answers
265 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 ...
Maciej Kravchyk's user avatar
5 votes
2 answers
411 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 ...
user1474326's user avatar
-1 votes
3 answers
1k 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, ...
rsp's user avatar
  • 143
-3 votes
1 answer
251 views

Testing a React component which receives a function as a prop

Suppose there's a root <App /> which houses multiple components, one of them being, say <SearchBox />. App component houses the app state (such as searchResults array) and iterates the ...
McDerp's user avatar
  • 75
58 votes
11 answers
15k views

If two individual branches pass unit tests, once they're merged, is the result also guaranteed to pass unit tests?

Suppose we have two branches A and B which have been forked from master. Both branches A and B make some changes and implement some unit tests. They pass all current and new tests, then are merged ...
kentrid's user avatar
  • 721
1 vote
2 answers
991 views

Unit testing a function that composes filters

Imagine there is a number of filter functions that all perform filtering of items in a list based on different criteria. Say there are 5 such filter functions. All unit tested Now imagine there is ...
keyermoond's user avatar
1 vote
4 answers
3k views

Should Unit Tests share the Same Data set?

We are writing application service tests across our Data Service Class. Currently writing tests liking add Product, remove Product, check for inventory after sale, etc. They are all using the same ...
user avatar

1 2 3
4
5
36