Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 106566

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

2 votes
Accepted

Unit Testing a class that requests data from multiple sources

There is nothing wrong with this method. It's pulling in a lot of information, but sometimes that's something that has to be done (e.g. for reporting, or preparing a large data transfer). It's inevita …
Flater's user avatar
  • 52.7k
1 vote

Should branching of functions be tested if not part of the contract?

How to test private members Every private member that is useful, is used in some way by a public behavior of that class. To put it another way: if a private member's existence/value has zero impact on …
Flater's user avatar
  • 52.7k
4 votes

How to do unit testing with complex business logic with lots of different code paths?

Proper separation of logic leads to avoiding the exponential growth that leads to "lots of different code paths". I suspect that you have not (or incorrectly) separated your logic, either mentally or …
Flater's user avatar
  • 52.7k
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 as we would …
Flater's user avatar
  • 52.7k
3 votes

Unit testing code which does not establish correlation between input and output

In most descriptions of unit testing as a methodology there's an idea of unit tests being as independent of implementation as possible. While I'm not sure if this is the core of your current questio …
Flater's user avatar
  • 52.7k
1 vote

Is setting up a basic happy path for the unit tests in a single place a good idea?

The answer to your direct question If the act itself is sufficiently complex, and there is value to its reusability, I see no reason to condemn this approach. As is often the case, the question isn't …
Flater's user avatar
  • 52.7k
2 votes

Purpose of unit testing simple methods

I completely recognize, that just trying to write tests for something, makes the code way better. As much as developers should be urged towards unit testing, your expectation is a bit off. Unit t …
Flater's user avatar
  • 52.7k
3 votes

Where did the guideline of writing automated unit tests for public methods (only) originate?

Exactly one of these things is true about a private member: In some way, it gets called when at least one of the class' public members are interacted with. It is not used and can be safely removed. …
Flater's user avatar
  • 52.7k
0 votes

How do I test a method which requires another method of the same class to be invoked first?

The code example you provided is somewhat nonsensical, but I assume this is intended as a trivial example, not real code. My answer is written under that assumption. AAA The basic AAA pattern helps i …
Flater's user avatar
  • 52.7k
10 votes

Why are unit tests failing seen as bad?

Phill W's answer is great. I can't replace it. However, I do want to focus on another part that may have been part of the confusion. In some organisations, apparently, part of the software releas …
Flater's user avatar
  • 52.7k
2 votes

Are parsers a special case in unit testing?

Unit tests don't care about private classes, because unit tests inherently don't care about the processing step. That is to say, unit tests don't care about parts of the processing. A unit test is in …
Flater's user avatar
  • 52.7k
0 votes

Should //given //when and //then comments be included in unit tests?

I want to come in with a different answer here, in favor of adding these comments. TL;DR Use these comments when they make sense. I'm all for it. But first, I want to be very clear here that this answ …
Flater's user avatar
  • 52.7k
3 votes

How to test a complex method (without rewriting it in the test)?

Jorg's answer is correct, avoiding complex methods is the way to go. But I wanted to add a practical example of how to segregate these (while trying to minimize the change required). for example a …
Flater's user avatar
  • 52.7k
5 votes
Accepted

How to test business logic in isolation when it depends on input validation logic

Your question touches on multiple issues. I've tried to decouple them as best as I can. Direct answers to your questions Is validation logic actually business logic and if so is it wrong to hav …
Flater's user avatar
  • 52.7k
0 votes

Testing for exception thrown, unit or integration test?

You're getting too granular with your definitions. Zoom out a bit. The language's framework is part of the language, and is not considered a component in the sense of a unit test, nor a mock, nor one …
Flater's user avatar
  • 52.7k

1
2 3 4 5
15 30 50 per page