Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
1answer
113 views

How can the `log` function be used for formal verification

In JavaScript I want to create a log function: function log(string) { console.log(string) } Obviously this causes side effects; it prints to the screen. And I have no control over its ...
1
vote
1answer
43 views

Spring Boot Controller Unit Test Strategy

All of the controllers in our project are as dumb as we can make them. Rightfully so, they simply validate the incoming payload, hand the request over to a service layer, and return whatever response ...
4
votes
3answers
157 views

Is checking for unexpected types in dynamic languages in an untyped project necessary?

In statically typed languages or dynamically typed languages that use a type checking system you can guarantee that the input type is the type that you specified in the contract. However, in ...
-1
votes
1answer
78 views

Is there a best practice for storing certificates (e.g. x509), which include private keys, used in unit tests?

In a software library, I wrote, large parts of the code use x509 certificates for various puprposes like signing documents digitally. Is there a best practice for storing test certificates used for ...
-1
votes
0answers
42 views

Using catch1.x with MFC GUI [closed]

I've recently started using catch1.x in a few minimal win32 console applications. I want to scale up to wrapping large (2000 DLLs) legacy MFC GUI applications in tests in order to make significant ...
-4
votes
1answer
76 views

What should I test with unit tests for data access layer? (MongoDB)

I'm working in TDD for my data access layer in MongoDB and I don't know what should I test? I think that I shouldn't test if the queries return what they have to return because It's a MongoDB concern....
4
votes
5answers
351 views

Should I Have One Interface Per Class For Unit Testing?

Should I define an interface for every public behavior class (excluding data classes)? I've spent many hours searching and reading to find a clear answer. If I search "Do you define an interface for ...
0
votes
1answer
54 views

Unit/Component testing using In Memory DB

I am writing Unit/Component test using In Memory DB. When I write Unit/Component test, I came across with the following question. I have the following two BL methods. ToCreate ToGet So when I ...
1
vote
1answer
97 views

Unit testing abstract classes with Google mock (gmock/gtest) (C++)

I want to test an abstract class with: Pure virtual methods that should be overridden in sub-classes Non-pure virtual methods that use the pure virtual methods (as opposed to this question) class Fu ...
1
vote
0answers
108 views

Unit testing C++ in XCode

I'm working on a plugin for some drafting software. The plugin takes the form of a dynamically loaded mach-o bundle. The software vendor provides a template plugin in the form of an XCode project. ...
0
votes
3answers
119 views

xUnit Should I Test Method Internal Work Or Only Result?

Let's take this unit test. Unit testing guidelines state that I should only have 1 assert per test, unless I'm testing the state of an object. In this case, Muxer.Muxe is a wrapper around FFMPEG that ...
-2
votes
1answer
85 views

What in practical-stupid-childish terms a mutation testing indicates?

Whlist browsing on github I came across the following project: https://github.com/infection/infection and according to the project's website https://infection.github.io/guide/#What-is-Mutation-Testing ...
1
vote
3answers
51 views

Calling functions to setup state before testing a related function

I believe the consensus on unit tests is that each individual test should interact with the smallest surface possible (?). I have a function I want to test, but it depends on some setup performed by ...
0
votes
3answers
125 views

Is is worth the time to create a list of manual regression tests for a legacy application?

I am part of a new dev team that is assigned to work on a legacy app. The app currently has no regression or automated unit, integration and system tests. Due to technical debt and convoluted ...
2
votes
2answers
176 views

How to organize my test functions? (Part II: Keepin' it classy)

What are the best practices to organize your unit tests in classes? I see different possibilities: 1) One would be to write one "container" class for each function you want test and then ...
0
votes
3answers
99 views

Should I create a shared Test Initilization object to initialize multiple test classes?

Scenario I'm a new developer, using MSTest and I've encountered the following issue: SomeClassTest // Uses a Fake Widget Controller. Test Initialize { Many lines of code to initialize Fake ...
4
votes
7answers
201 views

Rerun unit tests affected by change [closed]

Let's say we have a code base covered with big enough amount of unit tests. We make small change to the code and want to check if tests are still passing. Wouldn't it be great to be able to rerun just ...
91
votes
15answers
16k views

Should we design our code from the beginning to enable unit testing?

There's a debate going on in our team at the moment as to whether modifying code design to allow unit testing is a code smell, or to what extent it can be done without being a code smell. This has ...
1
vote
1answer
33 views

Should I run my tests against production build transforms (i.e. Babel)?

A coworker of mine recently setup testing in a new project (a JS library) where a transform step hooks in to the babel config for Webpack in the production config. For reference, this is the setting ...
0
votes
2answers
72 views

Unit testing about API endpoints and parameters

Consider a simple web application, I'll use a Python(ish) example, but i think the question is relevant for other languages as well. The user is trying to fetch a page, and in order to render that ...
-1
votes
2answers
104 views

Is QA/QC more related to proprietary softwares?

I'm not a software engineer, but I like coding for myself. Thus, I don't know what goes in IT companies. Keeping the amount I spend on GitHub, I never heard of the term QA/QC in regards to open ...
1
vote
2answers
98 views

Unit and integration testing of microservice architecture

I am investigating how to test a project. Some information about the project: Microservice architecture, with roughly 20 services. About 10 of them with a separate database. We use ServiceFabric ...
5
votes
2answers
348 views

Should my classes have separate constructors just for unit testing?

I like to write classes with two constructors: a primary constructor used in production code, and a default constructor just for unit tests. I do this because the the primary constructor creates other ...
0
votes
1answer
71 views

Unit testing for a method in a class which uses constructor DI (prism)

I have a class that uses constructor DI for IEventAggregator public SomeViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; ...
0
votes
2answers
54 views

How to name and organize unit tests with combinations of multiple parameters?

I am new to unit testing, but finally getting started. I have been running into a situation where my unit test names apparently grow too long to readable due to the multiple parameters and ...
-2
votes
1answer
73 views

Unit Tests - correct approach to test system with multiple layers

I'm wondering about Unit Tests. Let say i got a code ( in C#, but language is not important here): public class SOT: ISOT { List<string> _internalCollection = new List<string>(); ...
-2
votes
1answer
61 views

What is a common name for a module being tested?

When writing unit tests, I want to reduce the cognitive load of the reader as much as possible. One thing I've noticed that bothers me is that the variable names of the thing that is being tested are ...
-2
votes
1answer
64 views

How to identify test cases?

I wrote a small INI file parser as a library which I want to use in a bigger project. Following good practice I decided I should write test cases, too. But I fail to find a good start. The library is ...
1
vote
2answers
95 views

Should linters no-magic-numbers rule used in testing?

So I am just starting to use a linter and I like the no-magic-numbers rule in generally. But in unit test files it is giving me 1000 warnings. Here is what they look like: it('getWeekNumber', ...
2
votes
4answers
133 views

Testing database insertion, removal, and modification from program code (i.e., rather than test code)

I want to ensure that my program code is correctly inserting, removing, and modifying data in my database. Full integration testing can be slow, and I have concerns about keeping mock objects and data ...
-1
votes
1answer
39 views

Where do you put tests that are not unit tests in a Maven project?

I'm building a Spark-based, text analysis package using both Java and Scala. I have a series of transform functions, which take in one dataframe and spit out another, and that can be chained together ...
27
votes
2answers
3k views

Is a Unit test considered brittle if it fails when the business logic changes?

Please see the code below; it tests to see if a person with Gender of female is eligible for offer1: [Fact] public void ReturnsFalseWhenGivenAPersonWithAGenderOfFemale() { var personId = Guid....
5
votes
2answers
154 views

How to track C++ class traits?

As a fan of regular types and value semantics, I'm keen on classes becoming more regular and being non-polymorphic. As a fan of non-throwing operations, I'm keen on operations being noexcept. I also ...
0
votes
1answer
69 views

How to test an API that can change the response during time?

I currently use the Google trends API and I implemented a class to integrate with its services. As you probably know, Google trends tracks statistics which will change over time. So, when I write ...
3
votes
3answers
143 views

refactoring function to have a robust design

i am having a simple app example here: say i have this piece of code which handles requests from user to get a list of books stored in a database. from .handlers import all_books from flask import ...
7
votes
4answers
329 views

Should log statements be tested?

When writing tests I usually ignored logging statements, but now I wonder if it was right. The logs are often important tools when diagnosing production issues, moreover there can even be ...
2
votes
1answer
97 views

How to organize my test functions?

I'm writing a software application of a few thousand lines of code (in Python), and in order to keep the whole thing together, slowly but certainly the need for unit tests (and later, other types of ...
7
votes
8answers
341 views

Unit test which asserts that current thread is the main thread

The question is does it make sense to write a unit test which asserts that the current thread is the main thread? Pros/cons? Recently I've seen the unit test which asserts the current thread for the ...
1
vote
1answer
145 views

Unit testing protected methods which have no reason to be public

I need to make a sponsorship system with complex business requirements. Basically, after a user makes a payment, the system should get triggered. There are many different types of sponsoring, so I ...
2
votes
1answer
123 views

What's the purpose of xfail tests?

Some test frameworks, notably DejaGnu and py.test, have an "XFAIL" flag/status for a test which says that this test is expected to fail. If the test succeeds, it's marked as "XPASS" (unexpected pass). ...
0
votes
1answer
71 views

Testing - concise mocks vs asserting received calls

Let's say we have this method: string Add(int a, int b) { var sum = _calculator.Add(a,b); var response = _formatter.Format(sum); return response; } Now I want to unit-test this method. ...
0
votes
3answers
89 views

How to structure a set of classes that deal with external APIs for maximum testability?

I'm developing a set of classes designed to communicate with external APIs, and I'm running into trouble with how to properly structure everything for proper loose coupling and unit testing. ...
4
votes
2answers
224 views

How to engineer and test mission critical software?

TL;DR: My goal is to create some framework with which I could discover/test all possible internal states of my application so that I would approach with confidence for example engineering software for ...
2
votes
2answers
179 views

What is recommended way to create test data for unit test cases?

I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a core part of our application and there are number of scenarios in it, I want to write ...
1
vote
2answers
145 views

Peer review of unit test

What is a good strategy for Q/A Engineers peer reviewing Unit tests as part of the software development life cycle? I think that there are, indeed, things that I should check regarding the unit test ...
0
votes
1answer
76 views

How to write unit tests for my project

I'm relatively new to programming and have never written tests. I want to write unit tests for a group project (Angular web app with node background environment written in typescript), which you can ...
67
votes
6answers
10k views

How exactly should unit tests be written without mocking extensively?

As I understand, the point of unit tests is to test units of code in isolation. This means, that: They should not break by any unrelated code change elsewhere in the codebase. Only one unit test ...
-1
votes
1answer
97 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 ...
16
votes
7answers
4k views

Is it a good idea to write all possible test cases after transforming the team to TDD to achieve a full coverage?

Assume we have a large enterprise-level application without any unit/functional tests. There was no test-driven development process during the development due to very tight deadlines (I know we should ...
0
votes
2answers
320 views

Naming conventions for .net C# Unit test projects for better sorting [closed]

I currently use the following naming scheme for my unit test projects.. if I have a project "MyApp", I will have.. -- MyApp -- MyApp.Tests I see this is quite a common practice. Now, the problem is,...