Skip to main content
60 votes
Accepted

How should source code unit tests affect semantic versioning?

Your unit tests are not part of your public API. By definition, the API is a software interface that allows two or more systems, applications, programs, or components to communicate. The existence or ...
Thomas Owens's user avatar
  • 83.4k
25 votes

How do unit tests facilitate refactoring without introducing regressions?

There is a lot to digest in this question. There appear to be some misconceptions about unit tests, what exactly constitutes a "regression", and how much unit test code you should expect to ...
Greg Burghardt's user avatar
23 votes

How do unit tests facilitate refactoring without introducing regressions?

You're running into the classicists vs mockists debate or the sociable tests vs solitary tests debate. I may also suggest that the pyramid of tests may not be the only way to think about tests. Brian ...
Thomas Owens's user avatar
  • 83.4k
16 votes

How should source code unit tests affect semantic versioning?

Unit tests provide examples for the semantics of an API, hence they can be seen as part of the API's documentation. So when a change in a unit test shows a change of the API's semantics, this can give ...
Doc Brown's user avatar
  • 210k
14 votes

How do unit tests facilitate refactoring without introducing regressions?

Please allow me to begin with a pre-amble: this is not your fault. The literature sucks. Note that there is an emphasis on unit here. Yup; and there shouldn't be. "Unit test" was the ...
VoiceOfUnreason's user avatar
11 votes
Accepted

Should the unit tests be independent of the implementations

I have read that the changes to the code base should not change the unit tests. Close, but no. Lets fix that: Changes to the implementation choices, ones that change neither the behavior nor the API ...
candied_orange's user avatar
10 votes
Accepted

What is the correct way to configure a testing mode on a class?

You should use a different approach. The commonly advised approaches are Use DI to inject the firestore object into your repository class instance. This way, your test framework can just inject a ...
Bart van Ingen Schenau's user avatar
9 votes

Should the unit tests be independent of the implementations

I have read that the changes to the code base should not change the unit tests. Let me say this straight: this makes no sense. I don't have that book at hand, and you did not tell us which section ...
Doc Brown's user avatar
  • 210k
9 votes
Accepted

Approach to software testing with docker

Different kinds of tests are for different audiences. Those different audiences have different needs. The tests don't care where they are run. They care about the API they are run against and what the ...
candied_orange's user avatar
7 votes
Accepted

Is it worth unit testing hardcoded values?

Worth is subjective "Is it worth it" is generally not objectively answerable when talking about realistic testing expectations. Generally speaking, we don't get as much time to write tests ...
Flater's user avatar
  • 52.7k
7 votes
Accepted

Why are sealed classes not allowed to be mocked?

Mocking a class usually works by using reflection to construct a subclass which has methods and properties that do nothing (or whatever is required for the mock). "Sealed" classes cannot be ...
pjc50's user avatar
  • 13.7k
7 votes

Is low code quality and lack of testing the norm in B2B software development?

Kind of, but you are being fobbed off. these books that you've been reading are all written by developers in B2C companies No, B2C companies are just as bad/good as B2B and everyone writes books ...
Ewan's user avatar
  • 77.4k
7 votes

How do unit tests facilitate refactoring without introducing regressions?

You are absolutely correct. The "mockist" approach with mocking every dependency of a class or method leads to brittle tests which require a lot of work, makes refactoring difficult, and ...
JacquesB's user avatar
  • 59.9k
7 votes

TDD when removing long lived feature

You are feeling the pain that happens when tests are not written to be independent. Step one is making all of these tests independent. Break the dependency between testInitialDataCleared and all the ...
Greg Burghardt's user avatar
6 votes
Accepted

Testing for exception thrown, unit or integration test?

Doesn’t matter. I can throw an exception from a standard library by trying to open a file that doesn’t exist or by dividing an int by zero. What makes it a unit test only has to do with how you ...
candied_orange's user avatar
6 votes

Is low code quality and lack of testing the norm in B2B software development?

A horrible standard of quality from a practitioner's experience is certainly the norm in the industry, and as usual, it comes down to incentives. As long as customers are willing to pay for incomplete,...
Kilian Foth's user avatar
5 votes

How do I mock API responses with security in mind?

Rather than sprinkle such conditionals throughout your program, refactor the code so that all communication goes through a single, minimal communications specialist. Then replace that specialist with ...
Kilian Foth's user avatar
5 votes

Should edge cases be part of one test, or each their own case?

You are testing different aspects of the system under test, so those should be different test cases. However, you can use other techniques to reduce duplication. For example, you could extract the ...
amon's user avatar
  • 135k
5 votes

Is it possible to prove mathematically that unit testing reduces test effort as compared to integration testing?

I am not convinced that unit testing beats integration testing hands down in terms of man hours. Unit testing is not something that can beat integration testing. Unit testing is an effective way to ...
candied_orange's user avatar
5 votes

How should source code unit tests affect semantic versioning?

Unit tests should be a different piece of software from your application and hence not affect the versioning at all. Having said that, You would normally compile them all at the same time, and you ...
Ewan's user avatar
  • 77.4k
4 votes
Accepted

Where to put interface files for mocking aka what are best practices for organizing interfaces in a C#/.NET Core project with NSubstitute, Moq etc.?

Decisions like this are usually best guided by the Principle of Least Astonishment: What pattern will other developers recognize and understand quickly? First, C# projects have a very common ...
Stephen Jennings's user avatar
4 votes

Should Acceptance Criteria be mapped to unit tests?

I feel that part of this is common, BDD/Gherkin/Cucumber style testing where you write tests as acceptance tests and have them print out whether they work or not in that human readable format. Adding ...
Ewan's user avatar
  • 77.4k
4 votes

Should edge cases be part of one test, or each their own case?

Should these be in a single test case as a parameterized test because I am testing the same method - decrypt or encrypt - or should these be separate cases as I have them now? No. These might best ...
VoiceOfUnreason's user avatar
4 votes

Is low code quality and lack of testing the norm in B2B software development?

Poor quality is indeed the rule. Aside from anything else however, there isn't widespread agreement on what good quality looks like. Automatic tests only add a small increment of reliability, and ...
Steve's user avatar
  • 9,232
4 votes

How do unit tests facilitate refactoring without introducing regressions?

Note that there is an emphasis on unit here. Tests produced in this process are supposed to limit their scope only to the method I am changing; every method must be accompanied by a test that tests ...
Maciej Stachowski's user avatar
4 votes

Does testing the public surface of a class test the behavior of code or the way it is written?

Does testing the public surface of a class test the behavior of code or the way it is written? Yes. It depends on how the test was written. A good test is defined by the the System Under Test and the ...
Greg Burghardt's user avatar
4 votes

Benefits of resolving dependencies with IServiceCollection and IServiceProvider for Unit Tests instead of inheriting mocks from a base test class

Preconfigured Mocks or base test classes share a similar problem. Your tests can become more complex than what you are testing. The main benefit of Arrange, Act, Assert is that the whole test is ...
Ewan's user avatar
  • 77.4k
4 votes

How to decouple spagheti code for unit tests

Although you'll probably find good approaches to working with poorly-designed spaghetti code in the question that Kilian Foth linked to in the comment, since you're specifically interested in testing, ...
Thomas Owens's user avatar
  • 83.4k
4 votes

In unit testing: How to abstract a dependency of subject under test?

Mark Seemann makes a good point, but it's important to not take these things as a universal law, and understand them with more nuance. Your GetMenuList method might be too simple for this to apply, ...
Filip Milovanović's user avatar
4 votes
Accepted

.Net 8 XUnit: Should my tests use real data or how to mock MySql with CQRS?

The answer here is as often "depends what you're trying to test". If you're trying to unit test an edge case (e.g. that the application does not crash if the query errors), you almost ...
Philip Kendall's user avatar

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