Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
14
votes
1answer
203 views
Does it make sense to measure conditional coverage for Java 8 code?
I'm wondering whether measuring conditional code coverage by current tools for Java are not obsolete since Java 8 came up. With Java 8's Optional and Stream we can often avoid code branches/loops, ...
5
votes
2answers
162 views
What kind of unit tests should be written for a call to a database update function?
I'm dealing with a lot of functions like the one below and I'm unsure of what kind of unit tests should be written for them.
public void UpdateEmployeeClockIn(int employeeId)
{
var sql = string....
4
votes
2answers
61 views
Static services and testability
Where is the figurative line drawn for using static services in a project? I am a coop student working and learning how to write .net MVC projects. I've been developing trying to stick to TDD. In my ...
2
votes
3answers
95 views
Should you indirectly test private methods from within public method tests?
It seems to be fairly common opinion that you should only test public methods for a class or module and not private methods. If private methods are doing their job correctly, then that should be ...
12
votes
8answers
999 views
Is there an easier way to test argument validation and field initialization in an immutable object?
My domain consists of lots of simple immutable classes like this:
public class Person
{
public string FullName { get; }
public string NameAtBirth { get; }
public string TaxId { get; }
...
5
votes
1answer
238 views
Are programming languages unit tested? [closed]
I'm just wondering—Are the programming language features unit tested?
Basic features, i.e. built-in types, operators, arrays, generics, etc.
The question applies to unit testing for runtime behaviour,...
2
votes
1answer
107 views
Unit testing trivial cases [duplicate]
Currently we don't do much testing at our company, except some manual checking. We occasionally create some unit tests, integration tests and ui tests, but not on a regular basis. Since a new project ...
7
votes
2answers
20 views
How to test configuration changes in a service?
What is the best approach to testing a service when you add a new configuration?
For example my service offers a service to a customer and based on the customer configuration, it will offer a ...
6
votes
2answers
143 views
Is it bad practice for unit tests to be dependent on each other?
Lets say I have some sort of unit tests like this:
let myApi = new Api();
describe('api', () => {
describe('set()', () => {
it('should return true when setting a value', () => {
...
6
votes
1answer
167 views
Determining the best way(s) of adding unit tests to a large project that makes good use of stored procedures
We work on a fairly large casino/gaming/wallet/lottery platform. It's a turn-key application that is currently in use by 4 clients, and soon to be much more. I've made some bullet points regarding the ...
5
votes
1answer
150 views
How to write the first test for an “add” functionality
I had problems finding a good question title, so feel free to improve on that.
I want to implement an Entity Component System in C++, and wish to use TDD for the first time. Now I have doubts about ...
4
votes
2answers
108 views
Whether and how to test façades
In my application I have quite a few service classes that act as a façade and delegate most calls to one or more underlying manager classes. I've read very different opinions on how to test such ...
12
votes
3answers
398 views
How to start the habit of writing unit test as an employee? (or should I?)
I am working in a team that mainly write small PHP sites. Currently we don't have a habit of writing unit test. Testing are done by using the site as a user by our PM, who don't know how to code, and ...
1
vote
3answers
85 views
Is this testing practice unit testing, regression testing, and/or functional testing?
In a project, its program is written in C++, and implements some http service.
The testing program for the project is written in Python.
The Python testing program doesn't call the C++ project ...
0
votes
2answers
176 views
How would I test my matrix class?
I am currently working in my matrix class. After completion of the matrix I am planing to write a unit test for this matrix class testing all the functions that I wrote.
class Matrix{
Matrix(...
0
votes
0answers
44 views
unit testing a mocked class [duplicate]
I'm currently writing unit tests for my PHP code. I've read that unit tests should not interract with external elements such as network and filesystem.
In my code i have a curl wrapper class to ...
3
votes
2answers
250 views
My unit test looks very similar to the class I'm testing. How do I support my stance that the test is, in fact, correct?
I'm working on a boilerplate component that's supposed to generate a working sort-of "getting started" project structure. Think of it, in a web app context, of a component that will generate a ...
1
vote
1answer
127 views
How to not test implementation when method returns void?
Many places in stackexchange state that you should not unit test implementations, only the public interface of a class. But what if the public interface is a method that doesn't return any value, for ...
2
votes
2answers
102 views
Should I write duplicated tests for 'setDate' and 'isValidDate' methods?
Let's say I have a method called setDate. I also have another method called isValidDate to see if a string is a valid date string.
For convenience, setDate uses isValidDate internally as a mean of ...
1
vote
3answers
122 views
How specific do unit tests need to be?
I'm not really sure what/if there is a gold-standard on how much a unit test should be broken down. Another thing is sometimes I question whether I am wasting my time on a specific test. I am new to ...
0
votes
0answers
34 views
Is it wrong to pass the concrete Model through the View to the Presenter with MVP 'Passive View'
I have tried to implement the Passive View MVP in my WinForms application as much as possible. The Presenter is the only one who uses the Model and the Presenter responds to events that are generated ...
4
votes
4answers
349 views
How to write my own unit test?
I am currently trying to write a unit test of my own. The unit test I am writing is mainly for linear algebra (I know there are great package out there but I want to use my own for my project). My ...
1
vote
2answers
188 views
Mocking a file parser
I have a file parser and my manager told me that I need to create unit tests for it. Here is my code:
public class ParsedDetails
{
public int Id { get; set; }
public Guid Guid { get; set; }
...
5
votes
6answers
264 views
Stronger Unit Tests Unearth Many Bugs, What to do re Validations?
I recently upgraded some tests that unearthed a lot of previously hidden bugs. The bugs are rare and low priority, but they are still bugs and will eventually need to be fixed.
How should I handle ...
3
votes
3answers
154 views
Faking - Dependency vs Internal Details
Just for the sake of discussion below, when I refer to mocking, I mean mocking/stubbing/faking, as contrast to use real implementation in testing
I just had some discussion with my colleague during a ...
2
votes
2answers
94 views
How to keep unit tests well designed when structure of production code changes while avoiding related risk?
One of the main reasons for writing unit tests is to make sure that code still behaves the same way after refactoring. However, if interfaces change during refactoring, the tests need to be updated as ...
0
votes
1answer
47 views
Is using both Selenium and Mocha redundant?
I am learning React+Redux now and came to the testing section. Many people use Mocha or Jest to test React components, so far so good, makes sense.
I previously have experience using Selenium and I ...
1
vote
2answers
62 views
Is there any reason to use testing frameworks instead of assert for a lightweight lib of pure functions?
I've just written a simple mathematical library which consists of pure functions that take a few arguments, do some computation and return a result. I'd like to write unit tests for this library, but ...
0
votes
1answer
60 views
Is it okay to allow a custom assertion to return something?
This is language agnostic. I want to develop a simple custom assertion class using test driven development.
The class will have an assert method called assertCarIsNotDamaged which will check if a ...
0
votes
0answers
29 views
Should I create interfaces/abstract base classes when I only have a single implementation? [duplicate]
Lets consider a class "ClassA" that needs an instance of another class "ClassB", I can pass in this class in ClassA's constructor;
public class ClassA
{
private readonly ClassB _classB;
...
3
votes
1answer
99 views
Testing: why expect_any_instance_of is considered a design smell?
In this question, I'll use a ruby example, but I think it is a general question.
According to the most popular Ruby's test framework (RSpec), mocking any instance of a class (allow_any_instance_of) ...
4
votes
2answers
96 views
How to handle mocking equivalent methods without making tests fragile?
I am writing a unit test with mocks and I am concerned about over specifying the test. The idea being that if the implementation changes in a compatible way the test shouldn't fail since that makes ...
3
votes
1answer
268 views
In c# how do people make complex functions
Hi I'm working on a c# MVC code first project. I've started the project and have created the Models, database frontend etc.
Now my attention has come to writing something that can read an excel ...
0
votes
1answer
27 views
break down test class into multiple file naming convention
I have a test class with about 25 tests that are testing the different aspect of it.
I wonder
Should I break it down into smaller classes?
If so, then what is the best naming/packaging convention?
...
4
votes
0answers
106 views
How to unit test custom ClassLoader?
For some reasons, I need a child-first ClassLoader. Such ClassLoader doesn't exist in the JDK, so I'm writing it. Since this is a key component of my use case, I'd like it to be heavily tested. To ...
2
votes
4answers
76 views
Should I unit test the consuming class or the class running the logic?
I have a similar scenario to this:
public class VatCalculator
{
public decimal GetValueWithVat(decimal value, decimal? vatRatePercentage)
{
if(vatRate == null)
{
...
0
votes
1answer
61 views
Golden Data vs ?? (maybe Output Data?)
I'm just wondering if there's any popular terminology to refer to program output that is going to be compared to some canned golden data in a unit test. I'm trying to inject this terminology into my ...
0
votes
2answers
97 views
How to I best test this method? Do I need to split it up?
Okay, please consider the following method. Let me first tell you that my goals of the method is to determine if file system assets exist. That's to say this is an internal company site where you'd ...
0
votes
0answers
33 views
Unit testing $(jQuery).write() using method override
When unit-testing jQuery function, how does one substitute the .write method (method override) so that additional test programming can go in there?
$(jQuery).write("Hello, world!");
My desired test ...
1
vote
2answers
217 views
Why is so much attention given to unit testing (TDD) and so little to component level testing
This great articles explains the difference between unit testing, component level testing and UI testing. At all my previous companies great deal of attention was given to unit testing and less to ...
1
vote
3answers
153 views
Is it OK to create and drop databases during unit tests
I am working with EntityFramework 6 code first approach and SQL Server 2014 Express. However, the DBMS may change in future.
That setup allows easily to create a database and add some dummy data for ...
1
vote
3answers
310 views
C# / Java: Should every class have a main method?
I've been learning C# lately to see the other side of the coin (I have a decent amount of Java knowledge already) so I've been reading up on C#, and I came across an article called C# for Java ...
4
votes
2answers
114 views
Unit testing a software renderer, dealing with coupling due to speed issues
Unit testing is something I love now after forcing myself to do it in projects (and doing it at work) after seeing the massive rewards it offers down the road when refactoring and ensuring things work ...
0
votes
4answers
136 views
Should a unit test assert what a function doesn't do?
Sometimes I see bits of code in functions that I suspect could be changed in a specific way later that would break its functionality. For example, function A could be changed to call function B, but ...
1
vote
3answers
139 views
Reading a file before testing a method - it is an integration test or a unit test?
Let's say I write a parser. It takes an argument that is a String and does something with that. This String can be very long so keeping it in a test class can dirty my code. I think that it would be ...
76
votes
11answers
9k views
Shouldn't unit tests use my own methods?
Today I was watching a "JUnit basics" video and the author said that when testing a given method in your program, you shouldn't use other of your own methods in the process.
To be more specific, he ...
10
votes
3answers
159 views
Unit testing a class which uses DI without testing on internals
I have a class which is refactored in 1 main class and 2 smaller classes. The main classes use the database (like a lot of my classes do) and sends an email.
So the main class has an IPersonRepository ...
0
votes
0answers
62 views
How does Jenkins Pretested Integration Plugin handle conflicts?
To be sure that all code is tested before it gets to master, you can set up system, for example with Jenkins Pretested Integration Plugin, that works like this: You push code to a special integration ...
1
vote
1answer
60 views
Should integration test coverage allow for lower unit test code coverage? [duplicate]
If a project has 30% coverage by unit tests, 40% due to integration tests, is it fair to say the total is 70% as so moderately well covered?
Or are unit tests only ever used as the standard test ...
0
votes
1answer
37 views
Suggestions for best design pattern for unittesting Excel readin in Pandas
When I read about unittests I keep reading that I shouldn't rely on external resources, but in some cases I would like to test reading in Excel files so I can be confident this portion of my code is ...