Skip to main content

All Questions

1 vote
2 answers
342 views

Best Practice: Unit test coverage vs. in-method sanity checks [duplicate]

I have a code-coverage requirement of of a certain percentage, and face the following tradeoff: Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability? Lets ...
MPIchael's user avatar
  • 269
40 votes
9 answers
13k views

Testing the wording of an Exception message

Doing a code review, I ran into this assertion in a unit test: assertThatThrownBy(() -> shoppingCartService.payForCart(command)) .isInstanceOfSatisfying(PaymentException.class, exception -&...
Kricket's user avatar
  • 723
2 votes
2 answers
2k views

What is the difference between unit testing and handling exceptions

I have spent two full days now trying to understand the difference between unit testing and handling exception, but I can't get it. Things I have understood (or I think I have): Unit testing tests ...
Techoplite's user avatar
13 votes
4 answers
9k views

How should I write a test for a pure method which doesn't return anything?

I have a bunch of classes which deal with validation of values. For instance, a RangeValidator class checks whether a value is within the specified range. Every validator class contains two methods: ...
Arseni Mourzenko's user avatar
3 votes
1 answer
476 views

Modifying the tests and refactoring duplicate code in test driven development

I am trying test driven development for the first time (test first development, actually). I wrote down my specifications, then alternated writing tests, then code, writing the code to pass the latest ...
Benjamin's user avatar
  • 131
4 votes
2 answers
3k views

Is checking that a property doesn't throw an exception a valid unit test?

I'm writing tests for the following class: public class Foo : INotifyPropertyChanged { private int _failCount; private int _totalCount; public double FailRate { get { double ...
CurtisHx's user avatar
  • 1,177
1 vote
2 answers
998 views

Understanding unit testing for dynamically changing condition

I was trying to understand how to write unit tests for a few days now. I'm confused with following scenarios in the existing code. In first function the max value changes depending on the object ...
mssrivatsa's user avatar
3 votes
1 answer
5k views

Unit testing invalid inputs; ArgumentException vs. Custom Exception

In unit tested code I often have multiple checks on the arguments on any method before the actual "work" of the method is begun: public void DoSomething(string test) { if (string....
Ed James's user avatar
  • 3,499
23 votes
3 answers
47k views

Should I use try catch in my test methods?

I am doing unit testing. I am trying to test one function. I call it from my test component. But If remote function cannot handle the exception then my tester component will also get exception, I ...
Vikas's user avatar
  • 489