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

Getting Unknown Provider error when injecting a Service into an Angular unit test

I just ran into this and solved it by switching to getting the service using the $injector explicitly: var EventingService, $rootScope; beforeEach(inject(function($injector) { EventingService = $injector.get(‘EventingService’); $rootScope = $injector.get(‘$rootScope’); })); I wish I could tell you why this works and why the simple beforeEach(inject(function(EventingService) { …. })); does not, but I don’t have the time … Read more

Mocking vs. Test DB?

I think you’ll probably want to do some integration testing to check logic that is enforced by your database structure, for example constraints, triggers, autoincrement columns, etc. You should, however, for unit testing mock out whatever framework components that your DAL relies upon as you want (in your unit tests) to test only those components … Read more

Unit test HttpContext.Current.Cache or other server-side methods in C#?

The way to do this is to avoid direct use of the HttpContext or other similar classes, and substitute them with mocks. After all, you’re not trying to test that the HttpContext functions properly (that’s microsoft’s job), you’re just trying to test that the methods got called when they should have. Steps (In case you … Read more

How to mock EntityManager? [closed]

I suggest to use Mockito Framework it is very easy to use and understand. @Mock private EntityManager entityManager; If you want to use any method that belongs to entityManager, you should call. Mockito.when(METHOD_EXPECTED_TO_BE_CALLED).thenReturn(AnyObjectoftheReturnType); When you run your test, any call previosly declared in the Mockito.when for the EntityManager will return the value put in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)