Skip to main content
28 votes
Accepted

Why did JUnit declare setUp and tearDown in camelcase, even though each of them is a single word?

No, it shouldn't. For the moment, there is still a difference between the noun "setup" and the verb "set up": Hey Joe, can you set up the amp for me? Dude, that's a sweet stereo ...
Kilian Foth's user avatar
18 votes

Unit testing a void method

I would usually prefer method 2. Why? Because, you want postLogin to change some state of your system, but how it accomplishes this (and which methods it calls internally for this) is merely an ...
Doc Brown's user avatar
  • 220k
12 votes

Is performing integration tests on a production DB a bad practice?

It depends, but testing with production databases is typically a bad idea. Tests are for building confidence in your software The point of QA practices such as conducting tests is to build confidence ...
amon's user avatar
  • 136k
12 votes

Extending the class to test it: is this testing approach fine?

One of the dangers of testing is locking down an implementation. Tests should make it easier to refactor not harder. Tests that don’t focus on the public interface tend to lock down implementation. ...
candied_orange's user avatar
10 votes
Accepted

Are manually writing unit tests Proof By Example?

If you are randomly choosing inputs for testing, then I suppose it might be possible that you're exercising a Proof By Example logical fallacy. But good unit tests never do that. Instead, they deal ...
Robert Harvey's user avatar
8 votes

Are manually writing unit tests Proof By Example?

Any software testing is like "Proof By Example", not only unit testing using a tool like JUnit. And that is not new wisdom, there is a quote from Dijkstra from 1960, which says essentially the same: ...
Doc Brown's user avatar
  • 220k
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 ...
gnasher729's user avatar
  • 49.4k
6 votes

Extending the class to test it: is this testing approach fine?

Sometimes classes are designed such that they can only be used as a base-class but where you still want to test them independently of the existing derived classes. In such cases, the usual pattern is ...
Bart van Ingen Schenau's user avatar
6 votes

Why are test frameworks like JUnit or TestNG not more "object-oriented"?

The number one fundamental challenge with test frameworks is that it is not an object oriented problem. Initially, JUnit 1 was much more object oriented: There was a TestSuite object where you ...
Berin Loritsch's user avatar
6 votes
Accepted

Unit Test : Do I need to make an unit test for each class in my project

Business rules are the most important thing to test. Those should be in behavior objects (objects that DO things) not in value objects (getters and setters). Testing should never be done blindly or ...
candied_orange's user avatar
4 votes

Unit testing a void method

I would change getShoppingCart to something like initializeShoppingCart, the purpose of the method should be clear to whoever reads it without the need to check what the method does and side effects ...
Nastya S's user avatar
4 votes

Java design approach for "duplicated" class that are identical, except the import sources are different

In this situation, I would create an interface which would have the same signatures as the Message and CoolClass. Then you would simply create two implementations, one for Google and one for ...
JimmyJames's user avatar
  • 30.9k
3 votes

Java design approach for "duplicated" class that are identical, except the import sources are different

The classes from com.project.google/microsoft are autogenerated and there's nothing I can do to change them, including renaming. I am sure this is too pessimistic. You can surely write your own tiny ...
Doc Brown's user avatar
  • 220k
3 votes

Unit Test : Do I need to make an unit test for each class in my project

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious ...
VoiceOfUnreason's user avatar
2 votes
Accepted

Given an implementation of a Service Layer and Repository layer, should you make tests of both?

As hinted at it the comments, your ProductService at the moment seems to be an abstraction for the sake of having an abstraction. If you truly don't have any Product-related business logic, then test ...
Philip Kendall's user avatar
2 votes

Why are test frameworks like JUnit or TestNG not more "object-oriented"?

You asked Are there problems with this approach I'm not anticipating? An interface in Java or C# provides you only with a finite, fixed number of methods a class can implement. So your suggestion ...
Doc Brown's user avatar
  • 220k
2 votes

Extending the class to test it: is this testing approach fine?

Also, let's assume that I don't want to use libraries like PowerMockito (say, I don't want to deal with anything that uses Java Reflection API) and I want to keep it really simple. The simplest way - ...
Telastyn's user avatar
  • 110k
2 votes

Java design approach for "duplicated" class that are identical, except the import sources are different

Take a step back, and ask yourself: Is the code unrelated, and thus the automation reporting it as evil code duplication the problem? Or do both specimens solve the same problem and thus are identical,...
Deduplicator's user avatar
  • 9,309
2 votes

What's the reason for wiremock instead of Mockito in integration tests

Wiremock is designed specifically for integration testing, where Mockito is designed for unit testing. Wiremock describes itself as a "simulator for HTTP-based API's", whereas Mockito ...
Robert Harvey's 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 ...
Simon B's user avatar
  • 9,782
1 vote

Changing a class with static dependency injection to allow unit testing

Are there other way to solve the external dependency issue? DynamoDB is tightly coupled to Amazon. Amazon built it. Unless you can identify a higher level of abstraction, just leave your class as it ...
Greg Burghardt's user avatar
1 vote

Selenium and Junit: Does it make sense?

Selenium is a testing tool that is aimed at testing a browser-based user-interface, while JUnit is a testing tool that is designed for unit-tests and tests classes/components through their ...
Bart van Ingen Schenau's user avatar
1 vote

Should all third party methods that access outside resources (like other databases) be wrapped up?

Should all third party methods that access outside resources (like other databases) be wrapped up? Yes, pretty much. See Parnas, 1971. The core idea is that in our designs we create boundaries to ...
VoiceOfUnreason's user avatar
1 vote

Why are test frameworks like JUnit or TestNG not more "object-oriented"?

The JUnit test framework started a direct port of Kent Beck's SUnit framework/pattern [1][2] that arose roughly a decade earlier in the Smalltalk/Agile community. SUnit does feature individual test ...
amon's user avatar
  • 136k
1 vote

Unit testing a void method

When testing a function call (void or not) that has a side effect, it’s most complete to test that the side effect not only occurs, but to check that the side effect (system output or or state change) ...
hotpaw2's user avatar
  • 7,998
1 vote

How to drastically improve code coverage?

s. robins answer is very thoughtful and worth keeping in mind. particularly struggle with 'just wait and see', as frequently when a project goes over schedule, it's often because a legacy library had ...
joshua's user avatar
  • 121

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