mock

Concurrently node exits with status 1. This halts Teamcity leading it to believe that the tests failed

匿名 (未验证) 提交于 2019-12-03 10:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to run two scripts at once with concurrently . The basic command looks something like this: concurrently -k --success first "node ./tools/mock-webapi/mock-webapi.js" "npm run test-single-run" Which in turn calls (local): "test-single-run": "karma start --single-run --browsers ChromeHeadless" Or on remote (teamcity host): "test-teamcity": "karma start --reporters teamcity --single-run --browsers ChromeHeadless", The tests run just fine (local & remote). However, I keep getting exit code 1. Even if I use concurrently -k --success

AngularJS + Jasmine mock unit test $http factory of POST method

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How I can make unit-test of $http factory, if it using post method, for example: // controller $scope.logOut = function (){ logOutFactory.logOut().then(function(resp){ }); }; // service app.factory('logOutFactory', ['$http', '$q', 'CONST', function ($http, $q, CONST){ var logoutApiUrl = CONST.URL+'logout'; return { logOut: function() { var deferred = $q.defer(); $http({ method: "post", url: logoutApiUrl }) .success(function (data) { deferred.resolve(data); }) .error(function (data) { deferred.reject('error in $http request'); console.log

Mock redis template

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am facing a issue in mock redis template. Can any one help me to write unit test for below class. @Repository public class CasheRepo { @Autowired private RedisTemplate<String, Object> template; public Object getObject(final String key) { return template.opsForValue().get(key); } } And below is unit test class. But it is not working. It shows null point exceptions @RunWith(MockitoJUnitRunner.class) public class CashRepoTest { @InjectMocks private CasheRepo casheRepo = new CasheRepo(); private @Mock RedisConnection redisConnectionMock;

Mocking HttpContext.GetGlobalResourceObject in NUnit with Moq

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to write a unit test which tests a method that uses HttpContext.GetGlobalResourceObject() and I would like to mock it using Moq. Let's say we're testing this method: public List<DctmGridColumn> GetDctmColumnsMandatory() { List<DctmGridColumn> metadataFields = new List<DctmGridColumn> { new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint.Service", "DctmGridColumn_DispName_r_object_id").ToString()), new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint.Service", "DctmGridColumn_DispName_object_name")

Can JMeter mock HTTP request

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to Mock HTTP requests, meaning sending real request to real server , but ignore (not wait) and override the response with a dummy response, JMeter have many tools which are close but not enough, DummySampler plugin is close but not really sending request, An old answer direct to Mirror Server which seems irrelevant for specific API requests and responses. JMeter does not simulate servers. Having said that, JMeter 2.3 has a built-in mirror server - it accepts any HTTP request and responds with a page containing the request details. If

Python, mock: raise exception

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having issues raising an exception from a function in my test: ### Implemetation def MethodToTest(): myVar = StdObject() try: myVar.raiseError() # <--- here return True except Exception as e: # ... code to test return False ### Test file @patch('stdLib.StdObject', autospec=True) def test_MethodeToTest(self, mockedObjectConstructor): mockedObj = mockedObjectConstructor.return_value mockedObj.raiseError.side_effect = Exception('Test') # <--- do not work ret = MethodToTest() assert ret is False I would like to raiseError() function to raise

Runtime error PowerMock + Mockito: ProxyFrameworkImpl could not be located in classpath

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use PowerMock with the Android InstrumentTestCase Since my test runs on an Android device the libraries needs to be added to the apk. I encounter big issues with powermock+mockito and Dex files. I have a runtime error with only powermock+mockito in my dependencies: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath. And a compilation error if I include either cglib/cglib-nodep (has suggested in answers ): com.android.dex.DexException: Multiple dex files define Lnet/sf/cglib/beans

How can I mock sqlite3.Cursor

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been pulling my hair out trying to figure out how to mock the sqlite3.Cursor class specifically the fetchall method. Consider the following code sample import sqlite3 from mock import Mock, patch from nose.tools import assert_false class Foo: def check_name(name): conn = sqlite3.connect('temp.db') c = conn.cursor() c.execute('SELECT * FROM foo where name = ?', name) if len(c.fetchall()) > 0: return True return False @patch('sqlite3.Cursor.fetchall', Mock(return_value=['John', 'Bob'])) def test_foo(): foo = Foo() assert_false(foo.check

How to mock MyBatis mapper interface?

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing unit test for my Jersey rest API which uses MyBatis at the background. This is the structure of my classes: rest service: @Path("/api") public class HelloRestService { @Inject HelloBean helloBean; @GET @Path("/echo/{name}") public Response echo(@PathParam("name") String name) { return Response.status(200).entity(helloBean.sayHello(name)).build(); } } Stateless EJB: @Stateless public class HelloStatelessBean implements HelloBean { // Injected MyBatis mapper (dao) @Inject private EmployeeMapper employeeMapper; @Override public

What is the difference between jest.mock(module) and jest.fn()

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have tried couple different ways of defining the mock function and all of my tries failed. When I try to define it as follow: jest.mock('../src/data/server', ()=> ({server: {report: jest.fn()}})); expect(server.report.mock).toBeCalledWith(id, data, () => {...}, () => {...}); I get the this error: expect(jest.fn())[.not].toBeCalledWith() jest.fn() value must be a mock function or spy. Received: undefined If I define the mock as : var spy = jest.mock('../src/data/server', ()=> ({server: {report: jest.fn()}})); expect(spy).toBeCalledWith(id,