unit-testing

How do I unit test clojure.core.async go macros?

a 夏天 提交于 2021-02-06 15:24:30
问题 I'm trying to write unit tests when using core.async go macros. Writing the test naively, as follows, appears that the code inside the go blocks doesn't get executed. (ns app.core-test (:require [clojure.test :refer :all] [clojure.core.async :as async])) (deftest test1 [] (let [chan (async/chan)] (async/go (is (= (async/<! chan) "Hello"))) (async/go (async/>! chan "Hello")))) I've managed to get the following working, but it's extremely hacky. (deftest test1 [] (let [result (async/chan) chan

Mocking MediatR 3 with Moq

陌路散爱 提交于 2021-02-06 15:24:18
问题 We've recently started using MediatR to allow us to de-clutter controller actions as we re-factor a large customer facing portal and convert it all to C#. As part of this we are increasing our unit test coverage as well, but I've hit a problem when trying to mock MediatR itself. The command does a bunch of stuff to initiate a process and part of this is sending a notification. The notification itself is dealt with by its own handler and therefore would be subject to its own unit test so I

How do I unit test clojure.core.async go macros?

点点圈 提交于 2021-02-06 15:20:49
问题 I'm trying to write unit tests when using core.async go macros. Writing the test naively, as follows, appears that the code inside the go blocks doesn't get executed. (ns app.core-test (:require [clojure.test :refer :all] [clojure.core.async :as async])) (deftest test1 [] (let [chan (async/chan)] (async/go (is (= (async/<! chan) "Hello"))) (async/go (async/>! chan "Hello")))) I've managed to get the following working, but it's extremely hacky. (deftest test1 [] (let [result (async/chan) chan

Mocking MediatR 3 with Moq

心已入冬 提交于 2021-02-06 15:19:00
问题 We've recently started using MediatR to allow us to de-clutter controller actions as we re-factor a large customer facing portal and convert it all to C#. As part of this we are increasing our unit test coverage as well, but I've hit a problem when trying to mock MediatR itself. The command does a bunch of stuff to initiate a process and part of this is sending a notification. The notification itself is dealt with by its own handler and therefore would be subject to its own unit test so I

Testing listeners with Queue::fake()

夙愿已清 提交于 2021-02-06 15:18:55
问题 My Laravel 5.5 application has a Product model. The Product model has a dispatchesEvents property that looks like this: /** * The event map for the model. * * @var array */ protected $dispatchesEvents = [ 'created' => ProductCreated::class, 'updated' => ProductUpdated::class, 'deleted' => ProductDeleted::class ]; I also have a listener that is called CreateProductInMagento which is mapped to the ProductCreated event in the EventServiceProvider . This listener implements the ShouldQueue

Testing listeners with Queue::fake()

江枫思渺然 提交于 2021-02-06 15:17:33
问题 My Laravel 5.5 application has a Product model. The Product model has a dispatchesEvents property that looks like this: /** * The event map for the model. * * @var array */ protected $dispatchesEvents = [ 'created' => ProductCreated::class, 'updated' => ProductUpdated::class, 'deleted' => ProductDeleted::class ]; I also have a listener that is called CreateProductInMagento which is mapped to the ProductCreated event in the EventServiceProvider . This listener implements the ShouldQueue

Non-void test methods in JUnit 4

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-06 13:51:06
问题 I would like a JUnit 4 test class to implement the same interface as the class its testing. This way, as the interface changes (and it will, we're in early development), the compiler guarantees that corresponding methods are added to the test class. For example: public interface Service { public String getFoo(); public String getBar(); } public class ServiceImpl implements Service { @Override public String getFoo() { return "FOO"; } @Override public String getBar() { return "BAR"; } } public

Scrapy: effective way to test inline requests

半世苍凉 提交于 2021-02-06 12:48:44
问题 I wrote a spider using scrapy-inline-requests library. So the parse method in my spider looks something like this: @inline_requests def parse(self, response1): item = MyItem() loader = ItemLoader(item=item, response=response1) #extracting some data from the response1 try: response 2 = yield Request(some_url) #extracting some other data from response2 except Exception: self.logger.warning("Failed request to: %s", some_url) yield loader.load_item() I want to effectively test this method. I can

Scrapy: effective way to test inline requests

前提是你 提交于 2021-02-06 12:48:05
问题 I wrote a spider using scrapy-inline-requests library. So the parse method in my spider looks something like this: @inline_requests def parse(self, response1): item = MyItem() loader = ItemLoader(item=item, response=response1) #extracting some data from the response1 try: response 2 = yield Request(some_url) #extracting some other data from response2 except Exception: self.logger.warning("Failed request to: %s", some_url) yield loader.load_item() I want to effectively test this method. I can

Python Testing - Reset all mocks?

青春壹個敷衍的年華 提交于 2021-02-06 11:27:33
问题 When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks at the end of every file / module to avoid inter-file test pollution? It seems like something that is mocked in one Python test file remains mocked in other file with the same return value, which means my mocks are persisting between tests and files (when a patch decorator or with patch block is NOT used). Is there any way around