If unit testing is so great, why aren’t more companies doing it? [closed]

In my experience, there are a couple of factors involved in this: Management doesn’t really understand what unit testing really is, or why it has real intrinsic value to them. Management tends to be more concerned with rapid product delivery, and (incorrectly) sees unit testing as counterproductive to that goal. There’s a misperception that testing … Read more

F# development and unit testing? [closed]

Test-driven developers should feel right at home in functional languages like F#: small functions that give deterministically repeatable results lend themselves perfectly to unit tests. There are also capabilities in the F# language that facilitate writing tests. Take, for example, Object Expressions. You can very easily write fakes for functions that take as their input … Read more

How do I manage unit test resources in Kotlin, such as starting/stopping a database connection or an embedded elasticsearch server?

Your unit test class usually needs a few things to manage a shared resource for a group of test methods. And in Kotlin you can use @BeforeClass and @AfterClass not in the test class, but rather within its companion object along with the @JvmStatic annotation. The structure of a test class would look like: class … Read more

Service mocked with Jest causes “The module factory of jest.mock() is not allowed to reference any out-of-scope variables” error

You need to store your mocked component in a variable with a name prefixed by “mock”. This solution is based on the Note at the end of the error message I was getting. Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable … Read more

How to test my servlet using JUnit

You can do this using Mockito to have the mock return the correct params, verify they were indeed called (optionally specify number of times), write the ‘result’ and verify it’s correct. import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.io.*; import javax.servlet.http.*; import org.apache.commons.io.FileUtils; import org.junit.Test; public class TestMyServlet extends Mockito{ @Test public void testServlet() throws … Read more