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.

4
votes
4answers
631 views

Should I document a simple Unit Test project?

I have read questions like this: Are unit tests really used as documentation? With regards to code comments; my research so far is telling me: 1) Some developers do not like any code comments and ...
1
vote
2answers
499 views

Should I mock a Domain Service?

I am trying to decide whether to introduce mocks in my isolated Domain Model tests. I have a class method similar to this: public Offer AssignOffer(OfferType offerType, IOfferValueCalculator ...
8
votes
2answers
3k views

Should I include tests in Docker image?

When it comes to tests, I can think of two options: Put both test and application in one image. Include only application code in the image. Create a test-specific container that builds after the ...
0
votes
1answer
77 views

Should I be duplicating Equality methods in the test project?

I have read plenty of questions on here about overriding .equals and .hashcode for testing purposes only. My Domain classes have implemented .equals and .hashcode. Should I be 1) Duplicating these ...
4
votes
1answer
340 views

Should function composition and piping be tested?

Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable....
5
votes
3answers
570 views

Should all configurations and platforms run unit tests when application is in development stage?

I have open source C# .NET project at GitHub with Appveyor CI + code coverage. There are configurations like Release and Debug. There's also platforms like x86, x64 and Any CPU. This results to ...
-3
votes
1answer
118 views

Unit-testing function with multiple-dependency [closed]

I am trying to test a function that creates a message exchange graph from IRC chat logs. I am having trouble trying to mock the dependencies. The function makes use of util module. The functions ...
0
votes
0answers
35 views

How can I test an Express Controller that talks to 3rd party integrations?

I have a simple express server. There is a route that accepts both a NPS score and an email in it's req.params. Here: app.put('/api/nps/:score/:email', npsController.sendIntercomNPS) The actual ...
0
votes
1answer
100 views

How to plan unit-test design/structure for Javascript?

In opening I would like to say; I'm pretty new for programing. I'm working with JS for a year. Using Sencha's ExtJS and usign Bryntum's Siesta test tool for unit and integration(ui) tests. Right now ...
2
votes
4answers
191 views

How to write a unit test for a repository method that returns some data, where data can change over time?

I have some code that reads five numbers from a database: class Repository extends DatabaseRepository { function getCoefficients(string $model) { return $this->getDatabaseLink()-&...
0
votes
1answer
102 views

Unit testing certain tasks are done in a process

I have some Scala code that I wish to unit test using ScalaMock: class CancellationManagerSpec extends FlatSpec with MockFactory { "Cancelling a shipment" should "check shipment is not already ...
9
votes
3answers
447 views

Are manually writing unit tests Proof By Example?

We know that writing JUnit tests demonstrates one particular path through you code. One of my associates commented: Manually writing unit tests is Proof By Example. He was coming from the ...
-1
votes
1answer
75 views

How to approach writing a 'test' for a series of input->output sets, that will later be used to verify correctness of a new system?

I have a system ("an engine", which is a piece of code) that takes in several parameters returns some output. The input parameters are several distinct and constrained sets. I can enumerate all of ...
5
votes
3answers
3k views

What is black box unit testing?

I recently had my final exam for a software engineering course for my masters program and one of the questions on the exam was the following: Unit Testing is considered: a. White-box Testing b. Black-...
3
votes
1answer
335 views

Where should an on-team QC perform testing in a feature branching scenario?

I have searched and found a few questions talking about testing in relation to feature branching. My question is a little different. We are a scrum* team of 4 to 5 developers with a dedicated on-...
2
votes
3answers
811 views

Testing a class that uses external interface

I have a class that internally uses an interface that is defined externally. Testing this class becomes difficult since I need to mock out this interface but I am required to reference the external ...
3
votes
2answers
593 views

How to write good javascript unit test descriptions

I come from a python background. I typically write long unit test descriptions that link the test to a user story. The test is as much about justifying why the code exists and how it fits into the ...
1
vote
2answers
160 views

Is there a design pattern that I can use to simplify lots of nested methods

I'm trying to refactor some legacy code that's quite a mess. We're talking a class with 7000 lines and a handfull of methods that are violating the Single Responsibilty Principle so much it hurts to ...
1
vote
1answer
57 views

Mocked dependencies verification - Best practices

I have a simple question about best practices in unit test verifications. Given this example: @Test public void methodUnderTest() { when(mockedDependency.someMethod()).thenReturn(someValue); ...
-1
votes
2answers
334 views

Should I throw ArgumentNullException and should I test it? [duplicate]

Let's take an example of class with 3 dependencies and one method. class Example { private readonly IDependency1 _d1; private readonly IDependency2 _d2; private readonly IDependency3 _d3;...
3
votes
2answers
216 views

Is it sensible to structure unit tests in one class for executing the tests and one for the setup?

When writing unit tests for classes (especially when using DI and mocks) lately I often found it handy to structure my tests to one class actually running the tests and one responsible for the setup, ...
6
votes
5answers
16k views

Unit testing a void method

In order to fix a bug in an application, I modified a method named postLogin by adding a call to an existing method named getShoppingCart. Code protected void postLogin() { getShoppingCart(); } ...
6
votes
1answer
764 views

Does immutability reduce the scope of unit testing?

Recently, I worked on an Android project with Kotlin. As an architecture, there were immutable data classes and functions (not methods which are members of a class), where the functions generate new ...
6
votes
5answers
265 views

How should service method parameters be?

I'm just a junior developer but in about half a dozen projects I worked on there's always this situation: Service methods that take big objects as parameters, but often use just a little portion of ...
2
votes
2answers
184 views

Initialising variable within setUp() method or actual test method when changes are necessary?

I'm starting to wrap my head around PHPunit. My questions is the following. Whenever I use variables that do not change within my range of test methods I can initialize them within my setUp() ...
8
votes
4answers
384 views

What is the value of writing extra unit tests when re-factoring a larger function into smaller functions?

If I have a complex unit tested function: def do_everything(): # turn twizzles # push buttons # move mountain And I re-factor it into some smaller units: def do_everything(): ...
4
votes
4answers
428 views

Should you unit test order of operations? If so, how?

Imagine a psedo-code class like this which does name comparisons: public class NameComparer { public bool DoNamesMatch(Name name1, Name name2) { if(WholeNameMatch(name1, name2)) ...
1
vote
1answer
354 views

Making UnitOfWork testable

I'm in the process of refactoring legacy code. Unfortunately it is a WebForms application with very tight coupling and smelly code. Currently access to database is inside models which looks something ...
2
votes
2answers
236 views

Interrupting software development methodology

I'm in trouble, my team (3 devs including myself) works with mobile and backend development and we are dealing with some problems trying to order this process. Let me try to explain my situation, our ...
1
vote
0answers
42 views

Node JS Tape Unit Testing : All cases inside one function for a method

I am using tape for unit testing in Node JS. I wanted to ask one thing about better coding while writing unit testing. When using different inputs to a single method, is it a better idea to use all ...
84
votes
12answers
13k views

Is it considered 'bad practice' to check file contents/encoding in unit tests?

A bit of context: Earlier today I had to update some SQL code that another colleague of mine provided, and since it’s a pretty large script, it’s stored as a separate file (which is then read and ...
-1
votes
1answer
291 views

Unit Testing: Dependency Inversion

I'm trying to start adding some tests to my code. Please take it easy on me cause i'm still new to this stuffs. As far as i understand dependency inversion, all the dependencies will be place inside ...
3
votes
1answer
76 views

How to conduct software verification on embedded product?

I have developed an embedded product, which has a dot-matrix LCD, some buttons, bluetooth and WiFi functions. To me, the functions are rather complicated as one of the operating mode can interact or ...
0
votes
2answers
1k views

How do I go about unit testing a private method that gets called in a loop like this one? [duplicate]

How do I go about unit testing a private method that gets called in a loop like this one: // Calls MethodToUnitTest in a loop public static string Generate(params int[] values) { ...
1
vote
2answers
3k views

How to pass a mock as std::unique_ptr to Class under test

I am writing some test units using googletest and googlemock and I am stuck in a problem related to C++11 smart pointers and polymorphism. Suppose you have those classes: class A { public: ...
0
votes
3answers
633 views

Why are no parameters better than few parameter methods?

In Clean Code, Robert C. Martin states that no parameter methods are better than those with very few parameters. I'm kind of confused as no parameter methods are usually harder to unit test and tend ...
8
votes
4answers
543 views

Is implicitly depending on pure functions bad (in particular, for testing)?

To extend a bit on the title, I'm trying to get to some conclusion about whether it is necessary or not to explicitly declare (i.e. inject) pure functions on which some other function or class depends....
0
votes
1answer
120 views

Does it make sense to combine code coverage result for unit test and e2e test

In my company,There is a KPI about code coverage. We measure results by code coverage percentage. So we combine code coverage result of unit test and e2e test together. Is it make sense to do this ?
3
votes
3answers
886 views

Should Integration test offer more value than unit tests? [duplicate]

In order to ask this question I need to define a couple of terms to ensure everyone reading it is on the same page: Unit testing is the testing of a single class with all dependencies mocked / ...
6
votes
2answers
3k views

Testing - In-Memory DB vs Mocking

When writing tests, why would someone want to use an in-memory database over just mocking the data? I could see that in-memory databases could be beneficial for testing out one's repositories. But ...
1
vote
1answer
998 views

Testing a private method in Java [duplicate]

I am new writing good test cases, so please bear with me. Writing a test case for private methods public Stock getStock(String stockTicker) { Stock company = new Stock(); ...
13
votes
9answers
16k views

Should one test the values of an enum using unit tests?

If you have an enum with values only (no methods as one could do in Java), and this enum is part of the business definition of the system, should one write unit tests for it? I was thinking that they ...
6
votes
2answers
184 views

Should I use my own application's abstractions for test setup?

When doing test setup, is it better to use low-level APIs to get my system in the right state, or use the same abstractions that my application would use? I'm specifically interested in what promotes ...
1
vote
1answer
230 views

Testing strategy for a messy codebase

On an entry level for a codebase you are not familiar with, how do you introduce testing, an at what levels ? When introduced to codebases with no tests at all and at the same time being tangled ...
3
votes
2answers
189 views

How/if to test basic combinations of already tested functions

Sorry for the long-winded question. I hope the question and its potential answers can serve as a useful example to developers who are wondering where to set the bar regarding testing fairly simple ...
4
votes
2answers
411 views

Unit Test : Do I need to make an unit test for each class in my project

I have recently tried to to implement unit tests on a Java Web Application my project is built on MVC design architecture and uses Spring & JPA Hibernate and JSF here is a package tree -src -...
4
votes
3answers
2k views

Integration Testing: Testing Service to Service

I'm looking for some advice on testing strategies for service to service communication. I have one service (service A) that makes a call to another service (B) - which is a rest API. Both services ...
6
votes
4answers
662 views

Are unit tests written purely to satisfy a code coverage figure technical debt?

For reasons lost in the mists of time, your project has a code coverage standard. Unfortunately, some new code has gone in which takes the coverage below this figure. John Doe is duly assigned to ...
2
votes
1answer
132 views

Should I unit test my Cucumber helper functions/classes?

I'm very new at writing Cucumber tests. I'm writing Ruby helper functions to assist Cucumber step definitions. Should there be a separate set of tests to test my helper functions i.e. unit tests? The ...
5
votes
3answers
423 views

Unit testing private calls, or not

I have this method, which has multiple private calls: GetConfigStatuses(), ApplyFilters(), GetConfigListInfo(). Since these do not expose anything public I cannot test them like I would a public. ...