Make maven’s surefire show stacktrace in console

A related problem that I found is that surefire in recent versions apparently sets trimStackTrace to true by default (rendering most stack trace in failed tests useless), which is quite inconvenient. Setting -DtrimStackTrace=false or defining <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <trimStackTrace>false</trimStackTrace> </configuration> </plugin> solved this.

How to output in CLI during execution of PHP Unit tests?

UPDATE Just realized another way to do this that works much better than the –verbose command line option: class TestSomething extends PHPUnit_Framework_TestCase { function testSomething() { $myDebugVar = array(1, 2, 3); fwrite(STDERR, print_r($myDebugVar, TRUE)); } } This lets you dump anything to your console at any time without all the unwanted output that comes along … Read more

How do you unit test ASP.NET Core MVC Controllers that return anonymous objects?

Original idea from this answer with a more generic approach. Using a custom DynamicObject as a wrapper for inspecting the value via reflection there was no need to add the InternalsVisibleTo public class DynamicObjectResultValue : DynamicObject, IEquatable<DynamicObjectResultValue> { private readonly object value; public DynamicObjectResultValue(object value) { this.value = value; } #region Operators public static bool … Read more

Can I “fake” a package (or at least a module) in python for testing purposes?

Sure. Define a class, put the stuff you need inside that, assign the class to sys.modules[“classname”]. class fakemodule(object): @staticmethod def method(a, b): return a+b import sys sys.modules[“package.module”] = fakemodule You could also use a separate module (call it fakemodule.py): import fakemodule, sys sys.modules[“package.module”] = fakemodule

Django: How to create a model dynamically just for testing

You can put your tests in a tests/ subdirectory of the app (rather than a tests.py file), and include a tests/models.py with the test-only models. Then provide a test-running script (example) that includes your tests/ “app” in INSTALLED_APPS. (This doesn’t work when running app tests from a real project, which won’t have the tests app … Read more

how to fix 404 warnings for images during karma unit testing

That is because you need to configurate karma to load then serve them when requested 😉 In your karma.conf.js file you should already have defined files and/or patterns like : // list of files / patterns to load in the browser files : [ {pattern: ‘app/lib/angular.js’, watched: true, included: true, served: true}, {pattern: ‘app/lib/angular-*.js’, watched: … Read more