unit-testing

Simplify Django test set up with mock objects

你说的曾经没有我的故事 提交于 2021-02-07 08:17:26
问题 Often when I'm writing tests for my Django project, I have to write a lot more code to set up database records than I do to actually test the object under test. Currently, I try to use test fixtures to store the related fields, but could I use mock objects to mock out the related tables that take so much work to set up? Here's a trivial example. I want to test that a Person object will spawn() children according to its health. In this case, a person's city is a required field, so I have to

Mocking SparkSession for unit testing

本小妞迷上赌 提交于 2021-02-07 08:15:24
问题 I have a method in my spark application that loads the data from a MySQL database. the method looks something like this. trait DataManager { val session: SparkSession def loadFromDatabase(input: Input): DataFrame = { session.read.jdbc(input.jdbcUrl, s"(${input.selectQuery}) T0", input.columnName, 0L, input.maxId, input.parallelism, input.connectionProperties) } } The method does nothing else other than executing jdbc method and loads data from the database. How can I test this method? The

Mocking SparkSession for unit testing

余生颓废 提交于 2021-02-07 08:14:03
问题 I have a method in my spark application that loads the data from a MySQL database. the method looks something like this. trait DataManager { val session: SparkSession def loadFromDatabase(input: Input): DataFrame = { session.read.jdbc(input.jdbcUrl, s"(${input.selectQuery}) T0", input.columnName, 0L, input.maxId, input.parallelism, input.connectionProperties) } } The method does nothing else other than executing jdbc method and loads data from the database. How can I test this method? The

Get name of current test in setup using nose

回眸只為那壹抹淺笑 提交于 2021-02-07 06:56:43
问题 I am currently writing some functional tests using nose. The library I am testing manipulates a directory structure. To get reproducible results, I store a template of a test directory structure and create a copy of that before executing a test (I do that inside the tests setup function). This makes sure that I always have a well defined state at the beginning of the test. Now I have two further requirements: If a test fails, I would like the directory structure it operated on to not be

Does Boost have unit tests for itself?

我怕爱的太早我们不能终老 提交于 2021-02-07 06:19:06
问题 It is difficult to find information on this because of two reasons: Boost provides a unit test library. I am not referring to this, but have no means of communicating that to Google Building Boost from source involves the custom build system, b2 . Its help flag does not mention anything about tests. I would like to know if boost contains any tests for testing itself. For example many excellent open source libraries and applications have make check or make check-all or make test targets, but I

How to decide test cases for unit tests?

我是研究僧i 提交于 2021-02-07 05:32:24
问题 I'm just getting into unit testing, and have written some short tests to check if function called isPrime() works correctly. I've got a test that checks that the function works, and have some test data in the form of some numbers and the expected return value. How many should I test? How do I decide on which to test? What's the best-practices here? One approach would be to generate 1000 primes, then loop through them all, another would be to just select 4 or 5 and test them. What's the

How to test floats results with doctest?

大兔子大兔子 提交于 2021-02-07 05:01:08
问题 I'm developing a program that makes some floating points calculations. Is there any way to test my functions (which deliver floats) with doctests? 回答1: Sure, just format the floats with a reasonable format, based on your knowledge of what precision you expect them to exhibit -- e.g, if you expect accuracy to 2 digits after the decimal point, you could use: ''' Rest of your docstring and then... >>> '%.2f' % funcreturningfloat() '123.45' ''' 回答2: The documentation has a suggestion Floating

How to test on destroy scope

余生长醉 提交于 2021-02-06 15:31:27
问题 How to unit testing an $destroy event of a Directive in angularjs? I have the code in my directive: scope.$on('$destroy', function () { //clean something }); My test code: it('on destroy',function(){ scope.$destroy(); scope.$digest(); //expect everything done? }); Any suggestion! 回答1: You can select the DOM from the template of your directive and get the scope of it, then run $destroy(). Ex: your tpl: "<div id='tuna'></div>" your test: it('test on destroy', function(){ var isolateScope = $

How to mock service function in Angular component for unit test

余生长醉 提交于 2021-02-06 15:28:44
问题 I am writing unit test for angular app, I am testing if the service function returns a value. component.spec.ts import {TopToolBarService} from '../../top-toolbar/top-toolbar.service'; beforeEach(async(() => { TestBed.configureTestingModule ({ declarations: [ UsersListComponent], providers: [TopToolBarService],//tried mocking service here,still test failed schemas:[CUSTOM_ELEMENTS_SCHEMA] }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(UserListComponent);

How to mock service function in Angular component for unit test

妖精的绣舞 提交于 2021-02-06 15:28:39
问题 I am writing unit test for angular app, I am testing if the service function returns a value. component.spec.ts import {TopToolBarService} from '../../top-toolbar/top-toolbar.service'; beforeEach(async(() => { TestBed.configureTestingModule ({ declarations: [ UsersListComponent], providers: [TopToolBarService],//tried mocking service here,still test failed schemas:[CUSTOM_ELEMENTS_SCHEMA] }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(UserListComponent);