Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
110 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 ...
0
votes
1answer
79 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
56 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
1answer
46 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. ...
2
votes
2answers
187 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 ...
1
vote
2answers
125 views

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

I am new to TDD/unit testing. I am going to write one complex scheduling algorithm in Java. As this module is core part of our application and there are number of scenarios in it, I want to write ...
1
vote
2answers
101 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 ...
-1
votes
1answer
69 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 ...
-1
votes
0answers
119 views

Is it a code smell to expose a public method just for testing purposes? [duplicate]

Is it a code smell if the consumers of a class do not need a particular public method of the said class, but having the method simplifies its testing significantly? Consider the following example: ...
63
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
89 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 transform 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
97 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,...
-3
votes
0answers
70 views

Is putting related functions into a stateful class just for testability purposes a code smell?

Take the following JavaScript module as an example of a utility class helper file that exposes many related utility functions. This module initializes the state of module and the exported functions ...
2
votes
1answer
144 views

Unit Testability of Builder pattern

I'm looking at the builder pattern for helping setting up dependencies and parameters that may require complex logic for a class. But from the examples I've seen, the builder pattern does not seem ...
-2
votes
1answer
92 views

How can I unit test this code [closed]

How can I unit test a codebase which contains classes that includes two or three methods. In general these methods are too long. The methods contain lots of tasks like filtering datasets and a ...
-2
votes
1answer
50 views

Understanding property based testing

I'm reading about property based testing and I'm wondering how can I test this my code using that paradigm. class Invoice { private final String id; private final String companyName; ...
0
votes
2answers
111 views

DRY TDD + unit testing

Where/how do you draw the line for unit-testing classes at different levels of a hierarchy? For example, let's say you have a structure like this: public class Account { public Money ...
0
votes
2answers
106 views

How to unit test device driver initialization?

I am writing an IMU device driver in C using test-driven development methodology. As part of the driver, I pass a struct with user selected configuration settings to an initialization function which ...
4
votes
1answer
187 views

Wrapping utility classes and injecting them for unit testing purposes

I found that it is so hard to test classes that depend on other utility classes as java.nio.file.Files. It is also impossible to mock them using the classic unit testing stack (junit,mockito,..) ...
1
vote
2answers
134 views

Unit testing similar wrappers - or single unit test is enough?

I'm working on a service which has a lots of dependencies. The way how I call them is I'm wrapping each service client around an Adapter. Like this (I'm using Java): public abstract class AdapterBase&...
2
votes
4answers
192 views

Creating new constructors to overwrite the existing instance variables for testing purpose

Is it good/bad practice to add more constructors just for test purposes (to mock the DOCs used in my SUT) like this : public class A { private B b = new B(); private C c = new C(); ...
1
vote
1answer
31 views

NUnit specify TestCaseAttribute on implementation or create a test method

Based on this question about the correct usage of nUnit's TestCaseAttribute, I was wondering whether to specify the test case directly on the implementation or create test methods (as when using ...
9
votes
4answers
579 views

Refactoring - is it appropriate to simply rewrite code, as long as all tests pass?

I recently watched "All the Little Things" from RailsConf 2014. During this talk, Sandi Metz refactors a function that includes a large nested if-statement: def tick if @name != 'Aged Brie' &&...
0
votes
1answer
67 views

Unit tests involving library functions and objects

I am making a project using the Laravel framework. I plan to create unit tests for my project. But I feel I don't really have an idea what to test because I mostly use library or framework functions. ...
0
votes
4answers
228 views

What exactly caused the recent increase in automated testing?

Recently I've heard a lot about automating test is taking away manual jobs from the QA sector. When I look at example of what it is about most of it is just running a sequence of functions over and ...
0
votes
1answer
97 views

“Syncing” unit-tests for different layers

Consider unit tests for two (or more) consequent layers in web-application, backend, eg views (these are concerned with parsing form parameters, rendering the response) and actions (application logic)....
-4
votes
2answers
71 views

What relates to unit testing as requirements relate to system testing?

In system testing, a software system is tested against requirements. In unit testing, a software module is tested against the internal requirements for this module which depend on the specific ...
6
votes
5answers
757 views

Why is unit testing private methods considered as bad practice?

Context: I am currently working on a small project in Python. I commonly structure my classes with some public methods that are documented but mainly deal with the high level concepts (what a user of ...
1
vote
2answers
116 views

Is it good design to provide interfaces in a library that would only be used for unit testing?

Contrapositive-ish question: What is the design reason a library class would not implement an interface as a convenience to the developer? (e.g. the .Net library class FileInfo) The FileInfo class ...
3
votes
1answer
63 views

REPL-based Workflow and Unit Testing

As a developer who has primarily been doing functional programming in F# for the last several years, I'm very attached to my REPL and use it run my code as I go, testing and refining each function as ...
1
vote
3answers
274 views

Are unit tests needed for a function that only calls another function?

Assuming OldModule.oldFunc, if we want to move oldFunc to NewModule and, for backward compatibility, keep oldFunc there merely calling NewModule.newFunc by passing the exact same arguments and doing ...
2
votes
1answer
44 views

MVP Passive View -> Dependency Injection -> Factory Pattern -> Is testing behaviour whilst ignoring state enough?

I am writing an application using the Model/View/Presenter passive view pattern. I have view that contains multiple items in a list. My model is of type AudioDrama. For filtering that list I have ...
122
votes
15answers
19k views

How do you write unit tests for code with difficult to predict results?

I frequently work with very numeric / mathematical programs, where the exact result of a function is difficult to predict in advance. In trying to apply TDD with this kind of code, I often find ...
-1
votes
1answer
122 views

Unit Tests are duplicating the business logic

I have public class SomeDomainService { public SomeDomainService(IDependency1 someDependency1, IDependency2 someDependency2) { // ... } public void TestableMethod(int ...
7
votes
4answers
633 views

Should I test a method that calls a method that is already tested?

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) }...
0
votes
2answers
246 views

Unit Test a CRUD Controller MVC

I have looked through answers related to this but they don't seem to solve my problem. I am fairly new unit testing and testing as a whole. I just finished a small web application using ASP.NET Core ...
-3
votes
2answers
151 views

Is there such thing as minimum testing required when building a software?

As far as I know, ideally testing should be done extensively as hard and far as possible, however sometimes (always) we are required to ship quickly. In case of a delayed or a over-deadline projects, ...
5
votes
2answers
437 views

Should I be unit testing during prototyping/preparing for beta?

I am developing a web application for an industry that desperately needs it. Working with a consultant in the industry, I’ve rapidly developed a prototype in 2 months that we will be testing with a ...
1
vote
2answers
171 views

Is there any diagram for unit-tests?

I'm writing a software library for some numerical computations. I'd like to use Boost Unit Test framework to write a hierarchical unit-test covering not only basic input/output behavior of functions ...
1
vote
0answers
40 views

Unit testing multiple values [duplicate]

If I create a function to calculate the square root of a number, I suppose i should write a single unit test (maybe two, to test how it handles negative numbers). But what if I have a function which ...
3
votes
4answers
253 views

Should outgoing messages from object under test be tested?

I was watching a recording of a conference by Sandi Metz on testing. One of the things that I struggled with was that she said not to test outputs of the object under test (her example was query ...
0
votes
0answers
32 views

Calling other methods in unit test [duplicate]

I was learning about test driven development and came across unit testing. I have few questions regarding testing a class containing several methods; assuming i consider each of these methods a unit ...
1
vote
1answer
84 views

A performant and robust way to reset multiple files to its original state (TDD)

In our automated Java tests, we sometimes encounter issues, such as: Test A creates a custom file A.sh, that is then added on classpath Automated testsuite cleanup does not know about random file A....
6
votes
5answers
545 views

How far should I go with dependency injection and mocking?

Say I have a following class: public class A { public void execute() { if (something) ThirdPartyApi.method(); } } Now, I would like to test in particular the execute() method. I ...
2
votes
1answer
167 views

Handling hardware dependency while unit testing

I am writing a driver for an IMU sensor using test driven development approach. Communication protocol of choice is SPI. Using CubeMX and STM32F415 processor, SPI interface is implemented in ...
4
votes
5answers
522 views

Newbie question: Should all class public methods come from an interface?

I'm currently learning about TDD techniques, one of the suggestion is to test only public methods and skip the private ones. I have also been reading about Mocking. If I want to mock a certain method, ...
1
vote
4answers
248 views

Unit testing Markov chain code

What are the best ways to unit test code that outputs random sequences satisfying specific conditions, such as Markov chains? Let's be specific. There are two natural things to test: That the ...
0
votes
1answer
85 views

How to run machine-specific tests during DevOps remote build

What are the generally accepted means of running tests that pass on the dev machine on the build server where they'll consistently fail due to missing dependencies? (In this case, a configuration file ...
4
votes
2answers
301 views

TDD for Graphics application

I have googled and read few articles about the TDD for UI. I am not very much clear about how to start the implementation of the Graphics Application using Test Driven Development or how to write unit ...