Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?

Moq cannot mock non-virtual methods and sealed classes. While running a test using mock object, MOQ actually creates an in-memory proxy type which inherits from your “XmlCupboardAccess” and overrides the behaviors that you have set up in the “SetUp” method. And as you know in C#, you can override something only if it is marked … Read more

‘No JUnit tests found’ in Eclipse

Right Click on Project > Properties > Java Build Path > Add the Test folder as source folder. All source folders including Test Classes need to be in Eclipse Java Build Path. So that the sources such as main and test classes can be compiled into the build directory (Eclipse default folder is bin).

How to run only one unit test class using Gradle

To run a single test class Airborn’s answer is good. With using some command line options, which found here, you can simply do something like this. From version 1.10 of gradle it supports selecting tests, using a test filter. For example, For multi-flavor environments (a common use-case for Android), check this answer, as the –tests argument will be unsupported and … Read more

RubyMine Unit tests – Test Framework quit unexpectedly

There is a nice tutorial for setting up RubyMine tests in their online help, which helped me resolve the same problem as you describe (for Test::Unit-style tests). Basically you need to include the minitest and minitest-reporters gems into your project and add a call to use the new format of tests reporting: Take a look at the tutorial for more options.

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

Update: Some 10 years later perhaps the best way to test a private method, or any inaccessible member, is via @Jailbreak from the Manifold framework. This way your code remains type-safe and readable. No design compromises, no overexposing methods and fields for the sake of tests. If you have somewhat of a legacy Java application, and you’re not allowed to change … Read more

What are mock objects in Java?

A Mock object is something used for unit testing. If you have an object whose methods you want to test, and those methods depend on some other object, you create a mock of the dependency rather than an actual instance of that dependency. This allows you to test your object in isolation. Common Java frameworks … Read more