unit-testing

Python relative paths for unit tests

让人想犯罪 __ 提交于 2021-02-10 14:35:23
问题 Given the directory structure: /home/user/python/mypacakge/src/foo.py /home/user/python/mypacakge/tests /home/user/python/mypacakge/tests/fixtures /home/user/python/mypacakge/tests/fixtures/config.json.sample /home/user/python/mypacakge/tests/foo_tests.py /home/user/python/mypacakge/README.md Where src contains the source code, and test contains the unit tests, how do I setup a "package" so that my relative imports that are used in the unit tests located in test/ can load classes in src/ ?

How can I use a fake/mock/stub child component when testing a component that has ViewChildren in Angular 10+?

社会主义新天地 提交于 2021-02-10 14:33:25
问题 Before marking this as a duplicate of this question please note that I'm asking specifically about Angular 10+, because the answers to that question no longer work as of Angular 10. Background I've created a simple example app that helps illustrates my question. The idea with this app is that several "people" will say "hello", and you can respond to any or all of them by typing their name. It looks like this: (Note that the 'hello' from Sue has been greyed out because I responded by typing

How can I use a fake/mock/stub child component when testing a component that has ViewChildren in Angular 10+?

馋奶兔 提交于 2021-02-10 14:32:23
问题 Before marking this as a duplicate of this question please note that I'm asking specifically about Angular 10+, because the answers to that question no longer work as of Angular 10. Background I've created a simple example app that helps illustrates my question. The idea with this app is that several "people" will say "hello", and you can respond to any or all of them by typing their name. It looks like this: (Note that the 'hello' from Sue has been greyed out because I responded by typing

Is it possible to run tests on an in-memory assembly?

吃可爱长大的小学妹 提交于 2021-02-10 14:25:42
问题 I am currently building a mutationtest framework for .NET. I want to run the unit tests from a project on an in-memory assembly. This way the mutated assembly won't have to be writen to disk and my framework will be faster to use. Using the Roslyn compiler in .Net Core 2.0 I mutate (change) the syntaxtree and compile it into an in-memory assembly like this: Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms); Does anyone know of a way to unit test this assembly without writing

Unit Testing fromEvent observable with withLatestFrom

こ雲淡風輕ζ 提交于 2021-02-10 13:45:32
问题 I have the following observables: public ngAfterViewInit(): void { fromEvent(this.showFeaturesButton.nativeElement, 'click').pipe( takeUntil(this.ngUnsubscribe), withLatestFrom(this.store.pipe(select(fromClientStorage.getSubscription))) ).subscribe(([_event, subscription]) => { this.featureModal.open(FeatureListComponent, { data: { features: subscription.features }, }); }); } I am trying to test using: it('should call modal when feature button is clicked', () => { const subscription:

Python: How to mock SQLAlchemy event handlers (using mock.unittest)

谁都会走 提交于 2021-02-10 12:13:55
问题 So I have a SQLAlchemy model that has an event listener: class User(db.Model): id = db.Column(db.Integer, primary_key=True) @event.listens_for(User, "after_insert") @event.listens_for(User, "after_update") def do_something(mapper, connection, self): foo = SomeClass(self) foo.do_something_to_database() And I have a unit test that needs to update/insert the Model @patch('my_package.user.do_something') def test_user(mock_do_something): user = User() # This insert will invoke 'do_something' via

Mockito get all mocked objects

强颜欢笑 提交于 2021-02-10 12:07:29
问题 I want to get the list of all mocked objects. Using a previous version of Mockito I could do this: List<Object> createdMocks = new LinkedList<Object>(); MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); These listeners are removed in the latest 2.8 version of Mockito, is there any alternative for it? 回答1: Since Mockito 2.x this has been replaced by implementations of org.mockito.listeners.MockitoListener which you engage

Python: How to mock SQLAlchemy event handlers (using mock.unittest)

时间秒杀一切 提交于 2021-02-10 12:06:18
问题 So I have a SQLAlchemy model that has an event listener: class User(db.Model): id = db.Column(db.Integer, primary_key=True) @event.listens_for(User, "after_insert") @event.listens_for(User, "after_update") def do_something(mapper, connection, self): foo = SomeClass(self) foo.do_something_to_database() And I have a unit test that needs to update/insert the Model @patch('my_package.user.do_something') def test_user(mock_do_something): user = User() # This insert will invoke 'do_something' via

Django Unit tests issue : Import error

£可爱£侵袭症+ 提交于 2021-02-10 07:11:02
问题 I have the following project structure with Django 1.6: DjangoMain - app_1 - __init__.py - models.py - views.py - urls.py - test_views.py If I run the following command my tests are processed without any issue by Django: - python manage.py test app_1.test_views Creating test database for alias 'default'... ....... ---------------------------------------------------------------------- Ran 7 tests in 1.436s OK But, when I want to run all my test in all my app using the global test command

Issue with stubbing/mocking the method with makes a DB call

时间秒杀一切 提交于 2021-02-10 06:22:27
问题 I am having issue with Mocking a JDBC call using the MockitoJUnitRunner. Somehow Mockito is not mocking the actual call even though I have below subbing line into the test class. when(readOnlyJdbcTemplate.query(anyString(), any(Object[].class), any(int[].class), any(FeatureCollectionResponseExtractor.class))).thenReturn(actual); Very similar mocking is working in another class for very similar type of method. The only difference between them is my other class does have 3 parameters instead of