233
votes
Accepted
What's the point of running unit tests on a CI server?
Surely, by the time something gets committed to master, a developer has already run all the unit tests before and fixed any errors that might've occurred with their new code.
Or not. There can be ...
146
votes
Accepted
Are (database) integration tests bad?
Write the smallest useful test you can. For this particular case, an in-memory database might help with that.
It is generally true that everything that can be unit-tested should be unit-tested, and ...
93
votes
Are (database) integration tests bad?
One of my co-workers maintains that integration tests are all kinds of bad and wrong - everything must be unit-tested,
That's a little like saying that antibiotics are bad - everything should be ...
80
votes
Accepted
How exactly should unit tests be written without mocking extensively?
the point of unit tests is to test units of code in isolation.
Martin Fowler on Unit Test
Unit testing is often talked about in software development, and is a term that I've been familiar with ...
78
votes
Accepted
Are integration tests meant to repeat all unit tests?
No, integration tests should not just duplicate the coverage of unit tests. They may duplicate some coverage, but that's not the point.
The point of a unit test is to ensure that a specific small bit ...
78
votes
Is the usage of random values in unit testing a good practice?
Yes, I agree that randomness shouldn't be part of a testing suite. What you want is to mock any real randomness, to create deterministic tests.
Even if you genuinely need bulk random data, more than ...
77
votes
What's the point of running unit tests on a CI server?
As a developer who doesn't run all the integration and unit tests before making a commit to source control, I'll offer up my defense here.
I would have to build, test and verify that an application ...
66
votes
How exactly should unit tests be written without mocking extensively?
How exactly should unit tests be written without mocking extensively?
By minimising side-effects in your code.
Taking your example code, if calculator for example talks to a web API, then either you ...
65
votes
Accepted
How do I really write tests without mocking/stubbing?
This answer consists of two separate views on the same issue, as this isn't a "right vs wrong" scenario, but rather a broad spectrum where you can approach it the way it's most appropriate ...
64
votes
Accepted
Is it reasonable to not write unit tests because they tend to get commented out later or because integration tests are more valuable?
I tend to side with your friend because all too often, unit tests are testing the wrong things.
Unit tests are not inherently bad. But they often test the implementation details rather than the input/...
52
votes
Is the usage of random values in unit testing a good practice?
I've worked on projects which use anywhere from no to extensive randomness in tests, and I'm generally in favour of it.
The most important thing to remember is that the randomness must be repeatable. ...
47
votes
Accepted
How do integration tests criticize design?
Microtests can help lead to good design. By writing good small tests, you are deliberately testing a small amount of code and filling in its gaps with mock objects. This leads to low coupling (things ...
46
votes
Accepted
Is it possible/advisable to combine unit testing and integration testing?
Is it possible/advisable to combine unit testing and integration testing?
Doing both unit testing and integration testing? Overwhelmingly yes.
Mashing them together in a single test suite? Not ...
41
votes
What is the point of repeatedly executing the same test?
This is to allow you to detect the difference between passed, failed and flaky tests in a single test run.
A flaky test is one where it intermittently fails which can be due to a number of reason ...
39
votes
Accepted
Does integration testing use mocks?
If you have a piece of functionality that touches several external components, you might mock all but one to isolate and test a specific component. For example, suppose you have a function that calls ...
37
votes
Is it reasonable to not write unit tests because they tend to get commented out later or because integration tests are more valuable?
When major code changes occur, unit tests tend to be commented out rather than reworked.
With an undisciplined bunch of cowboy coders who think all tests getting "green" is fulfilled when you ...
35
votes
How exactly should unit tests be written without mocking extensively?
These questions are quite different in their difficulty. Let's take question 2 first.
Unit tests and integration tests are clearly separated. A unit test tests one unit (method or class) and uses ...
32
votes
Accepted
How can CI be used for interpreted languages?
Continuous integration as a term refers to two distinct ideas.
The first is a workflow: instead of everyone in a team working on their own branch and then after a couple of weeks of programming try ...
30
votes
How do integration tests criticize design?
The extremely short version: smaller tests, because they run smaller parts of the system, naturally constrain what the programmers can write, and so this creates an opportunity for sharper (easier to ...
28
votes
Accepted
Should I separate unit tests and integration tests?
In general: yes, you should put integration tests and unit tests into different folders. Often, programmers don't draw a clear line between these two kinds of tests and just write whatever kind of ...
27
votes
Which comes first: CD/Trunk-based development or microservices?
Consensus is you want CI/CD first and anyway, independent of your application's language, design or architecture. Whether you deliver trunk-based or use feature branching is also independent of CI/CD.
...
24
votes
How can CI be used for interpreted languages?
True, you do not have particular need of a CI system to perform builds and check that those builds are correct, but that is only part of what CI is about.
The purpose of CI is to detect errors as ...
24
votes
How do I really write tests without mocking/stubbing?
How do I really write tests without mocking/stubbing?
You design your code such that it can be tested without mocking and stubbing.
That's one of the important, if perhaps subtle, ideas behind TDD: ...
23
votes
What's the point of running unit tests on a CI server?
You'd think so wouldn't you - but developers are human and they sometimes forget.
Also, developers often fail to pull the latest code. Their latest tests might run fine then at the point of check-in, ...
23
votes
What's the point of running unit tests on a CI server?
Apart from the excellent Oded answer:
You test the code from the repository. It may work on your machine with your files... that you forgot to commit. It may depend on a new table that does not have ...
20
votes
Are (database) integration tests bad?
Unit tests don't catch all defects. But they are cheaper to set up and (re)run compared that other kinds of tests. The unit tests are justified by combination of moderate value and low-to-moderate ...
18
votes
Are integration tests meant to repeat all unit tests?
The short answer is "No". The more interesting part is why/how this situation might arise.
I think the confusion is arising because you're trying to adhere to strict testing practices (unit tests vs ...
17
votes
How do I really write tests without mocking/stubbing?
I'm self-proclaimed classicist myself, so let me clear things up a little.
First, the unit vs. integration tests. For me, 'unit' test is one that is independent of other tests and doesn't require any ...
16
votes
Accepted
What is the point of repeatedly executing the same test?
@Ewan posted a nice answer, but let me add this feature isn't only useful for potentially unstable or intermittently failing tests.
By using the RepetitionInfo argument, this can be used as a simple ...
15
votes
Accepted
Is testing behavior of many classes in one test still unit testing?
The outer limit of a unit is IO. If you're talking to peripheral's you ain't unit testing no more.
But within that you can carve things up as thickly or as finely as you see fit.
A test can exercise ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
integration-tests × 273unit-testing × 145
testing × 127
tdd × 42
continuous-integration × 29
database × 16
mocking × 14
acceptance-testing × 13
integration-testing × 13
c# × 12
bdd × 11
functional-testing × 10
rest × 9
java × 8
.net × 8
node.js × 8
test-automation × 8
python × 6
tests × 6
javascript × 5
php × 5
web-development × 5
web-services × 5
design × 4
programming-practices × 4