All Questions

2122
votes
42answers
561958 views

How do I test a private function or a class that has private methods, fields or inner classes?

How do I unit test (using xUnit) a class that has internal private methods, fields or nested classes? Or a function that is made private by having internal linkage (static in C/C++) or is in a private...
179
votes
8answers
321772 views

Mocking static methods with Mockito

I've written a factory to produce java.sql.Connection objects: public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory { @Override public Connection getConnection() { ...
553
votes
24answers
117218 views

How should I unit test threaded code?

I have thus far avoided the nightmare that is testing multi-threaded code since it just seems like too much of a minefield. I'd like to ask how people have gone about testing code that relies on thre...
9
votes
3answers
3882 views

DexIndexOverflowException Only When Running Tests

I can successfully build and run my Android app in my debug and release variants with no problem. Yet, when I try to run my new unit tests (I never had them before), I get the dreaded DexIndexOverflow...
242
votes
26answers
72267 views

Should I test private methods or only public ones?

I have read this post about how to test private methods. I usually do not test them, because I always thought it's faster to test only public methods that will be called from outside the object. Do yo...
314
votes
15answers
268989 views

How to run test methods in specific order in JUnit4?

I want to execute test methods which are annotated by @Test in specific order. For example: public class MyTest { @Test public void test1(){} @Test public void test2(){} } I want to ensure...
246
votes
11answers
246280 views

How to run JUnit test cases from the command line

I would like to run JUnit test cases from the command line. How can I do this?
439
votes
31answers
170518 views

How do you unit test private methods?

I'm building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it could be useful for future refac...
717
votes
13answers
503916 views

JavaScript unit test tools for TDD

I've looked into and considered many JavaScript unit tests and testing tools, but have been unable to find a suitable option to remain fully TDD compliant. So, is there a JavaScript unit test tool tha...
92
votes
4answers
32590 views

Using IoC for Unit Testing

How can a IoC Container be used for unit testing? Is it useful to manage mocks in a huge solution (50+ projects) using IoC? Any experiences? Any C# libraries that work well for using it in unit tests?...

Previous Next