testing

How to manually test input validation with NestJS and class-validator

大兔子大兔子 提交于 2020-05-16 08:54:28
问题 TLNR: I was trying to test DTO validation in the controller spec instead of in e2e specs, which are precisely crafted for that. McDoniel's answer pointed me to the right direction. I develop a NestJS entrypoint, looking like that: @Post() async doStuff(@Body() dto: MyDto): Promise<string> { // some code... } I use class-validator so that when my API receives a request, the payload is parsed and turned into a MyDto object, and validations present as annotations in MyDto class are performed.

How to manually test input validation with NestJS and class-validator

一曲冷凌霜 提交于 2020-05-16 08:52:32
问题 TLNR: I was trying to test DTO validation in the controller spec instead of in e2e specs, which are precisely crafted for that. McDoniel's answer pointed me to the right direction. I develop a NestJS entrypoint, looking like that: @Post() async doStuff(@Body() dto: MyDto): Promise<string> { // some code... } I use class-validator so that when my API receives a request, the payload is parsed and turned into a MyDto object, and validations present as annotations in MyDto class are performed.

ClassCastException in spring-kafka-test using `merger()`

我怕爱的太早我们不能终老 提交于 2020-05-16 06:27:09
问题 I want to test my Kafka Streams topology with a unit test using kafka-streams-test-utils. I'm using this library already a longer time and I built already some abstract layer around my tests using TestNG. But since I added a merge(...) to my Stream, I got the following Exception: org.apache.kafka.streams.errors.StreamsException: Exception caught in process. taskId=0_0, processor=KSTREAM-SOURCE-0000000001, topic=my-topic-2, partition=0, offset=0 at org.apache.kafka.streams.processor.internals

ClassCastException in spring-kafka-test using `merger()`

寵の児 提交于 2020-05-16 06:26:47
问题 I want to test my Kafka Streams topology with a unit test using kafka-streams-test-utils. I'm using this library already a longer time and I built already some abstract layer around my tests using TestNG. But since I added a merge(...) to my Stream, I got the following Exception: org.apache.kafka.streams.errors.StreamsException: Exception caught in process. taskId=0_0, processor=KSTREAM-SOURCE-0000000001, topic=my-topic-2, partition=0, offset=0 at org.apache.kafka.streams.processor.internals

Testing react-router with Shallow rendering

橙三吉。 提交于 2020-05-16 05:45:27
问题 I have my react-router component such as : <Switch> <Route path="/abc" render={() => <ComponentTemplateABC component={containerABC} />} /> <Route path="/def" render={() => <ComponentTemplateDEF component={containerDEF} />} /> ... ... </Switch> I wish to test the routing to ensure the respective component is rendered for each route. However, I do not wish to use mount for testing the routing, only wish to use shallow rendering. Below is what my test looks like currently: test('abc path should

How to use gmock to mock up a std::function?

北慕城南 提交于 2020-05-16 03:25:07
问题 The constructor of my class is A( ... std::function<bool(const std::string&, const std::string&)> aCallBack, ... ); I want to use EXPECT_CALL to test it. This callback is from another class B. I created a Mock like class BMock : public B { MOCK_METHOD2( aCallBack, bool(const std::string&, const std::string&) ); } Then I tried B *b = new B(); std::function<bool(const std::string&, const std::string&)> func = std::bind(&B::aCallBack, b, std::PlaceHolders::_1, std::PlaceHolders::_2); It still

how to view WTForms validation errors?

时光毁灭记忆、已成空白 提交于 2020-05-15 11:10:48
问题 I am writing some basic tests and have a test failing. def test_new_user_registration(self): self.client.get('/user/register') form = RegistrationForm( email=u'crow@crow.com', first_name=u'Alex', last_name=u'Frazer', username=u'crow', password=u'fake_password', confirm_password=u'fake_password' ) self.assertTrue(form.validate()) The assertion error is failing on form.validate() , but how can I view what the validation errors are? 回答1: Use form.errors: errors A dict containing a list of errors

how to view WTForms validation errors?

核能气质少年 提交于 2020-05-15 11:09:47
问题 I am writing some basic tests and have a test failing. def test_new_user_registration(self): self.client.get('/user/register') form = RegistrationForm( email=u'crow@crow.com', first_name=u'Alex', last_name=u'Frazer', username=u'crow', password=u'fake_password', confirm_password=u'fake_password' ) self.assertTrue(form.validate()) The assertion error is failing on form.validate() , but how can I view what the validation errors are? 回答1: Use form.errors: errors A dict containing a list of errors

Tools to coverage tests Django Rest Framework

百般思念 提交于 2020-05-15 06:07:17
问题 I am studying TDD and developing an API in Django Rest Framework, and I had a need that I researched and could not find some tools to solve my problem, I am trying to find out how much my tests cover my application in %. For know the number of possibilities and possible suggestions of what is missing cover, I found the coverage lib, but it generates a report with lots of data, which are not very useful for my case, I just want to know the coverage of my tests that I created. Does anyone know

Tools to coverage tests Django Rest Framework

强颜欢笑 提交于 2020-05-15 06:04:46
问题 I am studying TDD and developing an API in Django Rest Framework, and I had a need that I researched and could not find some tools to solve my problem, I am trying to find out how much my tests cover my application in %. For know the number of possibilities and possible suggestions of what is missing cover, I found the coverage lib, but it generates a report with lots of data, which are not very useful for my case, I just want to know the coverage of my tests that I created. Does anyone know