Posts

Showing posts with the label junit

Why JUnit test methods need to be void?

Image
Clash Royale CLAN TAG #URR8PPP Why JUnit test methods need to be void? I've read in lot of places that test methods should/must be void , but no one says what is the reason for this. void I found in MethodValidator the following check without comments/javadocs. if (each.getReturnType() != Void.TYPE) { errors.add(new Exception("Method " + each.getName() + " should be void")); } So why it should be void ? void Why would a unit test be anything other than void? Returning values from a unit tests method makes no sense, so if a unit tests method returns a value, it is probably not a correct unit test or not intended as a unit test. – Mark Rotteveel 10 mins ago 2 Answers 2 ...

Why is my Spring Boot Service test returning a NullPointerException?

Image
Clash Royale CLAN TAG #URR8PPP Why is my Spring Boot Service test returning a NullPointerException? Lately I have been trying to test my Spring Boo(2.0.3) Service, but I have been receiving a NullPointerException. The userDAOImpl implements the userDAO interface, Here is the serviceImpl class, it implements the interface Service: import app.clothapp.DAO.UserDAO; import app.clothapp.Model.User; import app.clothapp.Service.UserService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service public class UserServiceImpl implements UserService { Logger logger = LogManager.getLogger("UserServiceImplLogger"); @Autowired private UserDAO userDao; @Override @Transactional public void createUser(User user) { logger.debug(...

Set JUnit timeout in eclipse

Set JUnit timeout in eclipse Question When I run all our JUnit tests, using eclipse, can I set a default timeout? Background My manager insists on writing Unit tests that sometimes take up to 5 minutes to complete. When I try to run our entire test suite (only about 300 tests) it can take over 30 minutes. I want to put something in place that will stop any test that takes longer than 10 seconds. I know an individual test can be annotated with: @Test(timeout=10000) But doing this would make his long tests always fail. I want them to work when he runs them on his box (if I have to make minor adjustments to the project before checking it in, that's acceptable. However, deleting the timeouts from 40 different test files is not practical). I also know I can create an ant task to set a default timeout for all tests, along the lines of: <junit timeout="10000"> ... </junit> The problem with that we typically run our tests from inside eclipse with Right Click >...