New answers tagged

3 votes

Mock a bean with 10 methods when I only use one?

A number of options come to mind: Decompose ServiceTwo into an additional interface that ServiceTwo inherits from. This new parent interface would define the two methods that ServiceOne needs, or a ...
user avatar
0 votes

What is a good way to call a unit-tested function provided by a library/package?

Foo is a dependency. If you want to test it, import it and call the methods on it that are being used as part of your test suite. For example, if you are using Foo.X write some tests around the X ...
user avatar
  • 10.6k
1 vote
Accepted

What is a good way to call a unit-tested function provided by a library/package?

Encapsulating library functions makes most sense when your "own" interface main offers simplified access to the library, or at least provides a more precise or more readable name (assuming ...
user avatar
  • 184k
0 votes

Is it OK to have multiple asserts in a single unit test?

My (very late) 2cents: If your asserts are testing the state/result of your code and does not generate additional side effects in between any of the assertions, it's ok to have multiple asserts. You ...
1 vote

How to properly isolate tests for dataframes with grouping?

More generally what you are describing is a Data-Driven Test. To echo Kilian Foth's comment, each data frame is not a separate test case. Each data frame represents a different input to the same test ...
user avatar
0 votes

In testing is making asserts in cleanup bad?

Just make sure that (a) the failing assertion is detected, and (b) your unit testing software can handle this - it may not expect assertions during the cleanup and misbehave in some way. So with your ...
user avatar
  • 37.4k
4 votes
Accepted

In testing is making asserts in cleanup bad?

I am less concerned about DRY code in unit tests, and more concerned about the test clearly stating the intended behavior. Doc Brown has sensible advice, but I would prefer the assert in each test. If ...
user avatar
2 votes

In testing is making asserts in cleanup bad?

This is ok as long as your test runner lets you still see easily which specific test caused the assertion to fail the failing assertion does not prevent the cleanup of the resources up to the point ...
user avatar
  • 184k
3 votes
Accepted

Is it worth testing simple details?

Does worth testing simple details? Maybe? I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence -- Kent Beck, 2008 ...
user avatar
2 votes

Is it worth testing simple details?

Every unit of implementation code is an asset. Every unit test is a line in your insurance policy. You get to decide which assets are protected and how exactly how they're fixed or replaced when they ...
user avatar
  • 13.1k
4 votes
Accepted

Unit testing parts that use a Value Object that is being created by a Factory

how to write unit tests for the Services that depend on this Value Object without actually using the Factory in the unit tests? You add more layers of indirection. If you have "services that ...
user avatar
1 vote

Assert same and equals in unit test

There's no harm in having multiple assertions in one test. Provided that you are still testing one thing, not trying to test several different things in one test case. But as gnasher729 has pointed ...
user avatar
  • 8,560
6 votes

Assert same and equals in unit test

If you want to check that the object is the same and unchanged, the only way is to create a copy of the object first. Then you can check whether your original reference and the reference returned are ...
user avatar
  • 37.4k

Top 50 recent answers are included