Posts

Showing posts with the label Unit Testing

A Way To Output Pyunit Test Name In Setup()

Answer : You can use self._testMethodName . This is inherited from the unittest.TestCase parent class. def setUp(): print "In method", self._testMethodName self.id().split('.')[-1] You can find the Documentation at: http://docs.python.org/library/unittest.html#unittest.TestCase.id edit: For 2.7 users, https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.id You can use str(self.id()).split()[4] . It could be found here http://docs.python.org/library/unittest.html#unittest.TestCase.id

"Cannot Drop Database Because It Is Currently In Use". How To Fix?

Answer : The problem is that your application probably still holds some connection to the database (or another application holds connection as well). Database cannot be deleted where there is any other opened connection. The first problem can be probably solved by turning connection pooling off (add Pooling=false to your connection string) or clear the pool before you delete the database (by calling SqlConnection.ClearAllPools() ). Both problems can be solved by forcing database to delete but for that you need custom database initializer where you switch the database to single user mode and after that delete it. Here is some example how to achieve that. I was going crazy with this! I have an open database connection inside SQL Server Management Studio (SSMS) and a table query open to see the result of some unit tests. When re-running the tests inside Visual Studio I want it to drop the database always EVEN IF the connection is open in SSMS. Here's the definitive way to ...

Angular Unit Test Error: No Component Factory Found For Component. Did You Add It To @NgModule.entryComponents

Answer : Testing is doubting. More seriously, let me answer you. In Angular, your components are handled by a module. When you use Material dialogs and snackers, you actually use a feature of the CDK, which is called Portal . This allow you to create your components dynamically. But when you do so, you have to add them to the entryComponents of your module. You did it in your module, so you should also do it in your tests. The syntax is TestBed .configureTestingModule(...) .overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [YourComponent] } }); there are two places at which this is supposed to be done....entry components and also at declarations(while configuring your testing module).... TestBed .configureTestingModule({ declarations: [YourComponent], }) .overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [YourComponent] } }); If someone struggling to find BrowserDynamicTestingModule just use BrowserModule ...

Can Google Mock A Method With A Smart Pointer Return Type?

Answer : A feasible workaround for google mock framework's problems with non (const) copyable function arguments and retun values is to use proxy mock methods. Suppose you have the following interface definition (if it's good style to use std::unique_ptr in this way seems to be more or less a philosophical question, I personally like it to enforce transfer of ownership): class IFooInterface { public: virtual void nonCopyableParam(std::unique_ptr<IMyObjectThing> uPtr) = 0; virtual std::unique_ptr<IMyObjectThing> nonCopyableReturn() = 0; virtual ~IFooInterface() {} }; The appropriate mock class could be defined like this: class FooInterfaceMock : public IFooInterface { public: FooInterfaceMock() {} virtual ~FooInterfaceMock() {} virtual void nonCopyableParam(std::unique_ptr<IMyObjectThing> uPtr) { nonCopyableParamProxy(uPtr.get()); } virtual std::unique_ptr<IMyObjectThing> nonCopyableReturn() { r...

Android InstrumentationTestCase GetFilesDir() Returns Null

Answer : I think that you are right with keeping your test data separate from tested application. You can fix problem with Null by creating files directory for Instrumentation app by executing the following commands adb shell cd /data/data/<package_id_of_instrumentation_app> mkdir files You can do above only on emulator or rooted device. Then test from your question will not fail. I did it and also uploaded file named tst.txt to files dir, all below tests were successful: assertNotNull(getInstrumentation().getContext().getFilesDir()); assertNotNull(getInstrumentation().getContext().openFileInput("tst.txt")); assertNotNull(getInstrumentation().getContext().openFileOutput("out.txt", Context.MODE_PRIVATE)); But I think more convenient way to provide data to test project is to use assets of test project where you can simply save some files and open them: assertNotNull(getInstrumentation().getContext().getAssets().open("asset.txt"))...

Angular Unit Test Input Value

Answer : Inputs don't have textContent, only a value. So expect(field.textContent).toBe('someValue'); is useless. That's probably what's failing. The second expectation should pass though. Here's a complete test. @Component({ template: `<input type="text" [(ngModel)]="user.username"/>` }) class TestComponent { user = { username: 'peeskillet' }; } describe('component: TestComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [FormsModule], declarations: [ TestComponent ] }); }); it('should be ok', async(() => { let fixture = TestBed.createComponent(TestComponent); fixture.detectChanges(); fixture.whenStable().then(() => { let input = fixture.debugElement.query(By.css('input')); let el = input.nativeElement; expect(el.value).toBe('peeskillet'); el.value = 'someValue'; el.d...