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
-1 votes
1 answer
114 views

Efficient way to write test cases depending on a Micro service

I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a ...
Koushik Das's user avatar
7 votes
5 answers
724 views

How to initiate unit testing when you're the grunt?

I am the newest programmer on a very small team of 6 developers, 3 of which are offsite. By "newest" I mean both in years of experience (drastically) and familiarity with the code. I've been ...
tageta72's user avatar
  • 181
2 votes
3 answers
248 views

Method that returns an object is it adequate for TDD?

Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object. It starts to get really complex in my opinion and doesn't ...
Nmaster88's user avatar
  • 167
20 votes
8 answers
8k views

Why assert for null on a object before asserting on some of its internals?

Let's consider the following test. [Fact] public void MyTest() { // Arrange Code var sut = new SystemWeTest(); // Act Code var response = sut.Request(); // Assert ...
BAmadeusJ's user avatar
  • 326
0 votes
1 answer
675 views

Should I use my View Model to Test my Views in SwiftUI?

I was reading a post about testing in SwiftUI and the author said that don't write unit tests for your View Models that tests the UI of your view. The example he gave was a simple counter app. ...
john doe's user avatar
  • 141
2 votes
2 answers
595 views

Where do unit tests stop and integration tests begin according to the classical school of unit testing?

There are two schools of thought on how unit tests should be written. The first is the Classical/Chicago school, which focuses on the isolation of unit tests, describes a unit as a class or set of ...
B-Rad's user avatar
  • 203
4 votes
2 answers
506 views

How to write maintainable unit tests using classical style of unit testing

When I am using the classical style of unit testing, how do I keep the number of test cases for an object that has many collaborators from growing too large? And how do I keep the setup of each test ...
dbird's user avatar
  • 159
0 votes
0 answers
65 views

Unit testing with dependency on Word COM objects: Wrappers & interfaces vs document as an embedded resource

We are developing Word Addins that interact with elements in Word documents. To make it testable, my approach has been to use interfaces and wrappers for UI elements, and then provide mock alternative ...
Peter Dongan's user avatar
0 votes
4 answers
457 views

Dependency injection in legacy code

I have a legacy project with many classes with high coupling, and I have a necessity to test some of them. So, I decided to introduce dependency injection principle but stumbled upon where to create ...
Ruslan's user avatar
  • 9
2 votes
3 answers
339 views

Unit Testing Internal Classes

Advice on unit testing is often focused on publicly exposed classes. What about cases where the only public class is simply there to instantiate internal classes? Should the internal classes be unit ...
user12994244's user avatar
0 votes
1 answer
88 views

Do we need to test an integration of units if each unit has been tested against collaborator (mocks) and interface contracts?

Given: Let's say I have 3 objects A, B, C that form a cluster. Each unit (A,B,C) is independently tested with mocked collaborators. The "integration" is the call to A that calls out to B and ...
PhD's user avatar
  • 2,531
0 votes
2 answers
180 views

Testing an assertion across all test cases

I have recently developed a small module that performs queries against a database. At the end of each test that contains code performing modifying queries against the database, I added an assert that ...
krezno's user avatar
  • 167
0 votes
5 answers
883 views

Unit Testing - should / how should I write tests to cover new code that doesn't affect the interface of a method?

Having been trying to improve my unit tests, I'm trying to adhere to the principle of avoiding call verification. This is because it aligns with other principles I believe to be true: We Should test ...
gbro3n's user avatar
  • 491
0 votes
2 answers
271 views

Unit testing 'opaque' classes / structs

I'm sorry, no good title. I'm working on a C project right now and am writing tests. I usually do a 'struct method' style of programming. So I have opaque structs (no implementation revealed outside ...
Derek C.'s user avatar
  • 617
2 votes
1 answer
287 views

How to avoid class-proliferation when creating a unit-testable system?

I've been working on a personal project for some time, and I believe that I'm at that point where, if I don't embrace unit tests (and ideally TDD) now, it may be too late, so I want to make the right ...
Pablo's user avatar
  • 29
0 votes
1 answer
213 views

Path coverage and decomposition

Consider unit testing for a program written in procedural style. Each unit test tests a single function. Consider the following example, in which I use C_i(x) for a condition depending on the argument ...
AlwaysLearning's user avatar
0 votes
1 answer
569 views

What should you unit test in (external) service driven architecture?

My system consists of 4 seperate layers. API layer Application layer Infrastructure layer Core layer System is not Domain Driven. It contains no entities with domain logic. All models are anemic. ...
OverflowStack's user avatar
0 votes
1 answer
1k views

When unit-testing should common methods put in static class or in base class?

I have a few methods that are used from different class tests. Also, some other common methods are used for preparing the test data. What is the common practice to handle this in tests? Should I ...
theateist's user avatar
  • 101
-1 votes
1 answer
125 views

Software development in Python: unittests and assertions

I recently finished developing a piece of software in python where learning models and data processing procedures are contained within different class objects that succeed to each others (modules). As ...
JrCaspian's user avatar
  • 125
0 votes
1 answer
211 views

How to create useful tests for fixed byte values

I am working on an android application with Bluetooth iot devices. Theses devices sends broadcasts periodically in the form of 30ish bytes containing various information. Some of the bytes have ...
Lionel Briand's user avatar
0 votes
3 answers
183 views

Tests of 1-Dependency VS Tests of 0-Dependency

How many dependencies does a unit test have (that are not mocked)? My understanding is that a true "unit test" has zero dependencies, with all of them mocked (or none in the first place; ...
Dave Cousineau's user avatar
2 votes
1 answer
224 views

Test coverage for various code logic permutations... Metadata/Artifacts in algorithm results to describe which case?

I'm sorry if the title is confusing, I don't know if what I am describing has a proper name so let me describe... I have an algorithm which contains quite a bit of nested if/else if/else logic for ...
Mr. Boy's user avatar
  • 261
3 votes
1 answer
409 views

Why does this activity diagram not have the same amount of paths as the cyclomatic complexity number?

For the example shown below, in which I added the True and False values over the original document (so if something is wrong there, it's probably my fault), I understand there should be seven states ...
Alfred Kaminski's user avatar
2 votes
2 answers
256 views

Abstracting calls to common library methods in C#

I‘m working on making a legacy code base more testable and made good progress with (constructor)-injecting dependencies to classes. I noticed something in all classes that access the file system: they ...
Der_Reparator's user avatar
4 votes
5 answers
2k views

When mocking a class in a unit test, how should I handle dependency classes that have multiple similar get methods?

Let's say there's a class that processes text, and it gets that text from another class as a buffer. If this buffer class has multiple get methods, like readLine(), readChar(), readCharCode(), how ...
krazune's user avatar
  • 41
8 votes
10 answers
1k views

Can you have too much unit test coverage?

Google tells me that the ideal unit test coverage is 70 - 80% (although Google's source for that doesn't look especially credible). This old post suggests that in fact it depends on what gives you ...
OutstandingBill's user avatar
0 votes
1 answer
2k views

Mocking / stubbing C# record types in a unit test

I have a series of record types in my C# project that I use with JSON.Net to deserialize json data. public record RadarrMetadata( IReadOnlyCollection<string> CustomFormats ); public record ...
void.pointer's user avatar
  • 5,083
0 votes
2 answers
143 views

Writing tests for API that results depends on table with millions of rows

I think my problem is very common but I couldn't phrase it correctly in the title. I have a Django API that returns some information about companies (like address, partners, situation, etc) given its ...
Bruno Mello's user avatar
8 votes
3 answers
623 views

How can you write unit tests for an opaque/nondeterministic algorithm like Monte Carlo tree search?

I've written an implementation of the UCT1 Monte Carlo Tree Search algorithm for selecting moves in a two-player game. In the future, I'd like to expand this implementation to use more advanced tree ...
Derek Thurn's user avatar
2 votes
2 answers
344 views

Should mocks used in unit tests represent entireties or subsets?

I was working on a unit test that has a mock object looking something like: public class TestMock { static { Doodad a = new Doodad(0); Doodad b = new Doodad(1); Doodad c = ...
pstatix's user avatar
  • 1,047
0 votes
1 answer
133 views

Do you test your CI/CD scripts? [closed]

Is it common to write test for CI/CD scripts? Background: Some CI/CD jobs/scripts have become rather complex over the years (new features, edge cases) and I believe it would help rewriting them with e....
gebbissimo's user avatar
1 vote
2 answers
1k views

C# - Class creating instances of other classes requiring different services

Context I have a service class whose sole purpose is to interact with a specific API, let's say the Automotive API. The API mostly works with generic AutomativeRecord which basically represents a ...
Union3008's user avatar
0 votes
0 answers
78 views

Unit test coverage and abundant glue code [duplicate]

How do I solve this riddle of contradicting "good practices" to properly cover my app with unit-tests? These are principles I found about writing unit-tests: Pyramid of testing says unit-...
Gherman's user avatar
  • 945
0 votes
4 answers
652 views

Should i write tests if it takes more time than testing manually?

Im making a website and trying to learn Test Driven Development (TDD) I'm doing one of CS50 projects, were we need to make a website to trade stocks. I decided to use this oportunity to learn TDD. I ...
Portho Games BR's user avatar
10 votes
9 answers
7k views

Is it bad practice to compare string representation on an object instead of its properties during unit tests?

Given a class as follows: class IntList { public: IntList(std::vector<int> list) : m_list(list) {} std::vector<int> list() { return m_list; } std::string toString() { ...
Delgan's user avatar
  • 366
0 votes
5 answers
337 views

What arguments to use when explaining to a team that one does not write unit tests in a different language?

I'm helping a software team to embrace a transition to DevOps and I realized that they struggled a lot with testing. The one point that troubles me the most is that they absolutely want to write unit ...
avazula's user avatar
  • 125
-3 votes
3 answers
210 views

Where did the guideline of writing automated unit tests for public methods (only) originate? [closed]

The question is simple: there is no shortage of opinions that state automated unit tests are to be written only for public methods. What is the authoritative source and argument behind this best ...
ragnacode's user avatar
  • 109
10 votes
3 answers
3k views

Why is having bloated interfaces an anti pattern?

[I'm using the term interface here with C#'s interface in mind. I won't tag the question with a C# tag because it really isn't a C# question.] In my work we do unit and integration tests but we don't ...
underthevoid's user avatar
0 votes
1 answer
1k views

Mock a bean with 10 methods when I only use one?

I face some situations similar to the following simplified one: @Component class ServiceOne { @Autowired ServiceTwo two; void act() { ... two.a(); ... } } @...
ch271828n's user avatar
  • 181
2 votes
2 answers
285 views

What is a good way to call a unit-tested function provided by a library/package?

Consider the function foo provided by package X in Python. I want to test the different functionalities of X.foo, and then use X.foo in my code. To make sure that I am using X.foo as it was tested, I ...
mhdadk's user avatar
  • 131
0 votes
1 answer
214 views

How to properly isolate tests for dataframes with grouping?

I have the following problem: I would like to test complex business logic for each test case completely separately, i.e. all tests should run in parallel. I don't want the test for customer #43 to ...
komodovaran_'s user avatar
3 votes
3 answers
781 views

In testing is making asserts in cleanup bad?

As a learning excercise, I decided to take a hand on Test Driven Development. Now I decided that there is a test I want to make; check if database connection doesn't leave any unsaved changes. The two ...
vakus's user avatar
  • 133
0 votes
2 answers
210 views

Is it worth testing simple details? [closed]

In front-end projects(made in frameworks like Angular or React), when we correctly encapsulate complex functionalities, the components that really have some relation to the business logic normally ...
Vitor Figueredo Marques's user avatar
0 votes
1 answer
750 views

Unit testing parts that use a Value Object that is being created by a Factory

Here is the conundrum, I have a fairly complex Value Object and I don't want to expose it's internals. It should not be an Entity since there is no need for attaching an identity to it. According to ...
Tetra's user avatar
  • 3
-1 votes
2 answers
686 views

Assert same and equals in unit test

I have a function to be tested fn doNothing(Student student) { //do some other operations here. but student is unmodified return student; } And my unit test is var student = new Student("...
Santhosh Thamaraiselvan's user avatar
14 votes
3 answers
3k views

Should I choose repeated code in unit test or test logic? Can I avoid both?

When writing unit tests, I feel that there is a trade-off between code repetition and test logic. Example of my current (likely flawed) approach: To test this function (overly simple function for ...
Jasper Braun's user avatar
0 votes
1 answer
837 views

Unit tests and mocking when functions arguments have changed?

I'm learning how to write unit tests on a project I'm doing with my friends. One thing we tried was to mock the return values of function calls if the functions are declared in a different "...
learningtech's user avatar
1 vote
4 answers
1k views

Is setting up a basic happy path for the unit tests in a single place a good idea?

I've come in to a project where it's a best practice for an Init method for all tests in a class to contain mocked happy path functionality. This should allow most methods to pass without exceptions. ...
cah1r's user avatar
  • 302
4 votes
1 answer
481 views

Should I unit test "trivial" functions that are thing wrappers around the Pandas API?

I'm working on a codebase with very little testing. The code is 90% an ETL pipeline with functions like def sort_data(df: pd.DataFrame, column: str = 'date') -> pd.DataFrame: return df....
MYK's user avatar
  • 343
2 votes
4 answers
393 views

How can unit testing be employed to discourage developers from changing structurally-critical code?

Imagine a system for loan applications where loans can be in one of three states: PENDING, APPROVED, REJECTED. Over time, people create code, UIs, internal reports, etc. that assume there are only 3 ...
user2923125's user avatar

1
2
3 4 5
36