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 ...
Oded's user avatar
  • 53.5k
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 ...
Jeff Bowman's user avatar
  • 1,890
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 ...
D Stanley's user avatar
  • 1,185
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 ...
VoiceOfUnreason's user avatar
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 ...
Kilian Foth's user avatar
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 ...
Flater's user avatar
  • 47.7k
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 ...
TZHX's user avatar
  • 5,062
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 ...
David Arno's user avatar
  • 39.1k
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 ...
Flater's user avatar
  • 47.7k
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/...
Denis de Bernardy's user avatar
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. ...
l0b0's user avatar
  • 11.3k
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 ...
Thorin Jacobs's user avatar
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 ...
Flater's user avatar
  • 47.7k
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 ...
Ewan's user avatar
  • 72.4k
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 ...
FrustratedWithFormsDesigner's user avatar
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 ...
Doc Brown's user avatar
  • 203k
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 ...
Kilian Foth's user avatar
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 ...
amon's user avatar
  • 134k
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 ...
J. B. Rainsberger's user avatar
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 ...
amon's user avatar
  • 134k
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. ...
Martin Maat's user avatar
  • 18.3k
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 ...
Iker's user avatar
  • 865
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: ...
VoiceOfUnreason's user avatar
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, ...
Robbie Dee's user avatar
  • 9,737
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 ...
Borjab's user avatar
  • 1,339
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 ...
Nick Alexeev's user avatar
  • 2,514
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 ...
Warbo's user avatar
  • 1,205
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 ...
Euphoric's user avatar
  • 37k
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 ...
Doc Brown's user avatar
  • 203k
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 ...
candied_orange's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible