Skip to main content

New answers tagged

5 votes
Accepted

How to avoid too much mocking in unit tests in a database-heavy method?

How can I avoid excessive mocking and reduce the tight coupling between the tests and the implementation? Don't mock things. Or only mock things you cannot otherwise test. If your service requires a ...
nvoigt's user avatar
  • 8,435
5 votes
Accepted

Should I skip unit tests if integration tests cover the same scenarios?

What is an integration test? and integration tests should be written for pieces of code that interact with external systems, like databases. Firstly, while this is not the main point of the answer I ...
Flater's user avatar
  • 54.9k
-1 votes

Reusing constants in tests vs "magic" values

Using constants in test rather than magic values improves readability, maintainability, consistency, and overall code quality. its makes the intent behind the code clearer and ensure that changes can ...
david ekeh's user avatar
2 votes

Reusing constants in tests vs "magic" values

I would really question the value of these "is the correct error thrown in X circumstance" tests. Presumably you are not hand coding the error code and message for every error. You have some ...
Ewan's user avatar
  • 78.5k
4 votes
Accepted

Reusing constants in tests vs "magic" values

First, it is never a good idea to distribute knowledge about the correct value for something like NAME_LENGTH_LIMIT over too many places in the code. Ideally, there should be a single source of truth. ...
Doc Brown's user avatar
  • 212k
2 votes
Accepted

Is testing multiple, concurrently running instances of the same class an integration test?

Already established in another answer, the "unit" in unit test does not exclusively refer to a single class. Sometimes a handful of classes work together as a unit, at which point they can ...
Flater's user avatar
  • 54.9k
-1 votes

Is testing multiple, concurrently running instances of the same class an integration test?

The outer limit for a unit test is IO. No DB, no file system, no networking. So it depends on where these events are going. If you're sending them to some event server this isn't a unit test. If you'...
candied_orange's user avatar
5 votes

Is testing multiple, concurrently running instances of the same class an integration test?

The "unit" in "unit testing" isn't necessarily a class. As Wikipedia correctly states: Unit is defined as a single behaviour exhibited by the system under test (SUT), usually ...
Doc Brown's user avatar
  • 212k
1 vote

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

Why is global state hard to test? Global state is a subtle way of coupling every function that uses it. Setting the state before each test case is all fine and well, but guess what's not happening in ...
Filip Milovanović's user avatar
2 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

Trusting a global is like eating off the floor. why would it be "harder to test"? Because a global is known, globally. doesn't "setting the global state at the beginning of each test&...
candied_orange's user avatar
6 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

One thing i don't see anyone else bringing up here is the set of unique bugs that global state makes more likely. Especially raceconditions become a lot more likely to occur in an application with ...
Anders Martini's user avatar
4 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

I think you're conflating two things, basically the words "any" and "all". Does there exist global state that can be tested in the way you describe? Yes. In a suitable language you ...
Steve Jessop's user avatar
  • 5,161
1 vote

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

There are already good answers, but one additional consideration for some cases: Global state management (reset and access) likely will require global initialization, i.e. to first reset the global ...
Frank Hopkins's user avatar
16 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

My question is, why would the answers assume that? Because it is the default unless you change it. If I need to test a function with a global state, isn't just "restoring the global state at ...
nvoigt's user avatar
  • 8,435
1 vote

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

I don't think there is one universal understanding of what "global state" even is. I suppose it is commonly used as a synonym for "global variables" - that is, a facility offered ...
Steve's user avatar
  • 10.3k
60 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

How do you know where all the global state is in your application? When you have a function which does not use global state, all the information required for test state is in the parameters. When a ...
pjc50's user avatar
  • 14.6k
35 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

If you reset the global state before each test, each test will execute in a known global state and will, therefore, be consistent. Trouble is, that's not how it will be executed in the real ...
Phill  W.'s user avatar
  • 13k
7 votes

Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?

In an application, you usually start with global state initialised from settings and preferences, and then you add more state as the application is running. When you call a method in real code, it ...
gnasher729's user avatar
  • 46.7k
-2 votes

How to follow Outside-In TDD with Micro-services and Micro-frontends?

As per all other answers on this post, here is the summarized version of how we can implement the Outside-In TDD for micro-services, where one micro-service is dependent on another to complete any ...
Jignesh M. Khatri's user avatar
2 votes

How to follow Outside-In TDD with Micro-services and Micro-frontends?

Your top level acceptance test just needs a stable API to act through. It doesn't matter how many micro-services are needed to support it. What matters is, as you flesh out the micro-services, you ...
candied_orange's user avatar
2 votes

How to follow Outside-In TDD with Micro-services and Micro-frontends?

Your case will allow it to write outside-in tests on three different levels (at minimum): outside tests for the "system as a whole" - which are real integration tests, showing the different ...
Doc Brown's user avatar
  • 212k
0 votes

How to follow Outside-In TDD with Micro-services and Micro-frontends?

The main point of microservices is that they are separate. A microservice has some API, and there are consumers of that API. If another service needs some new API they make a feature request, you ...
JonasH's user avatar
  • 5,840
4 votes

How to follow Outside-In TDD with Micro-services and Micro-frontends?

There's not just one feature where a single feature can span across several Micro-services? For all intents and purposes, this isn't one feature spanning across several microservices, this is a ...
Flater's user avatar
  • 54.9k

Top 50 recent answers are included