Questions tagged [tdd]

1

votes
1

answer
42

Views

Golang: reflect.DeepEqual returns unexpected false

I have the following code and code test below and for some reason the deepEqual is returning a false and failing the test. Now from reading the doco on this I would expect this to pass with a true for something so simple? Any points would be much appreciated. Thanks // customer.go type Customer stru...
Luke Hamilton
1

votes
1

answer
1.6k

Views

Process of testing with TypeORM and Nestjs, and jest using mocks?

This question can likely be generalized to stubbing repositories in a service and how to properly test and provide coverage in the context of this question. I am in the process of learning more about testing, but am stuck with how to properly perform testing that involves the DB. I have a User ent...
kyle
1

votes
3

answer
62

Views

How to assert that a method call was not made, without any_instance?

I have a class, that in one situation should call :my_method, but in another situation must not call method :my_method. I would like to test both cases. Also, I would like the test to document the cases when :my_method should not be called. Using any_instance is generally discouraged, so I would be...
Matilda Smeds
1

votes
3

answer
53

Views

When to stop when trying to write meaningful tests using TDD?

I'm struggling to find when to stop writting test cases using TDD. Let's say a have to write a method that only accepts some strings, it can only accept the strings ['red', 'green', 'blue'], it is required and can't be empty. I write the first failing test, make it green, and so on and so forth unti...
Guilherme Amorim
1

votes
2

answer
53

Views

How to use the url that came in response

Help to understand and direct what needs to be done further. I use the robot framework version 3.1.1 and the Python 2.7 programming language to write the autotest script, and now there is a task to develop a test that will work with POST / GET requests. So, I make a POST request to the system to ini...
Геннадий
1

votes
1

answer
353

Views

How do you stub a method to return an array

I have DocumentService class like this: namespace App\Services; use App\Api\StorageServiceInterface; class DocumentService { private $storageService; function __construct(StorageServiceInterface $storageService) { $this->storageService = $storageService; } public function createFolder(User $user) {...
Raghavendra N
1

votes
1

answer
45

Views

Enzyme/Jest — Writing TDD with DOM tree

Using shallow component, how do I test something like this that has DOM API (querySelector for instance) handleOnClick(e) { const { pageID } = this.props document.querySelector('form .event').name = '_eventID' + pageID document.querySelector('form').submit() e.preventDefault() } My test is breaking...
Alejandro
1

votes
1

answer
39

Views

How do I stub a method in an object that is loaded in my class/method under test?

Our MEANJS application has a class (E.g., CompanyService) that loads an object (E.g., CompanyRepo) of another class and calls a method on it. I am trying to write unit tests for the CompanyService class and would need to stub a method in the CompanyRepo method to simulate a promise rejection. Howev...
Agni Barathi
1

votes
1

answer
500

Views

how to 'properly' write tests in typescript

i really love tdd, and want to pick up a new language, and have chosen typescript. Unfortunately i'm struggling to write tests the way i want to. say i am testing the following class: class Container { private numbers: number[]; constructor(){ this.numbers = []; } addNumber(numberToAdd: number) : v...
ocstat
1

votes
0

answer
135

Views

Rails5 - test if current URL is equal to routed path

I created a test to confirm that after a failed post request to a signup form the current url is the same it was before. This in the case the default RESTful route takes the place of the custom url. My test passes, but I think is not complete and/or there's a mistake. PROCESS: creation of a signup p...
John S.
1

votes
1

answer
71

Views

Design MVC Controller using TDD for database calls

I am new to MVC and unit testing. I need to do unit testing on my controllers but I'm afraid I may not have them setup properly. For example: public class MyController { public ActionResult Index(int id) { var locations = new MyLocations().GetLocations(); //linq code here that filters based on id...
Legionpete
1

votes
1

answer
1.1k

Views

“Cannot read property includes of undefined” error in Jest and Enzyme

I have a React component which is used to render Checkbox. The component code has a function which looks like this: const generateCheckboxes = (array, filterType) => { return array.map((filter, i) => { if (!isNullOrUndefined(filter) && filter !== '') { const applied = props.appliedFilterList[filterT...
pranami
1

votes
1

answer
78

Views

Django PUT TestCase fails if client initialised in setUpTestData() but passes if client initialized in setUp()

I am writing tests where every test case passes except the PUT from django.test import TestCase from rest_framework.test import APIClient class ViewTestCase(TestCase): @classmethod def setUpTestData(cls): cls.client = APIClient() def setUp(self): '''setUp() runs before every single test method.''' s...
Abhinav
1

votes
2

answer
107

Views

How to verify that multiple sorts have been applied to a collection?

I'm implementing sortable columns on my Kendo grid and the user-expected behaviour is to allow multiple columns to be sorted at the same time. Naturally, I'm starting off by writing a unit test to be able to verify that the sorting is (by default) first by Ref ascending, then Name ascending. Test su...
Ilessa
1

votes
2

answer
44

Views

Can’t find best way for apply best in code design techniques in software dev

[Pre] I have to say that I'm dummy newbie who is trying to get together important puzzles with such crucial details as DDD, TDD, MVVM, and EFCore. I have an about 10 years of windows form develop experience in complete wrong manner, and after I'm joined to Plurasight I'm understood that I'm just lo...
Max Zaikin
1

votes
0

answer
127

Views

How to make tests with Django using real data?

Here is my situation: We have a project that started by the wrong way, without testing. The Project uses Python 3.6* and Django 2.*. Anyway, now we are trying to code the tests and for this we are reading 'Obey the Testing Goat' book, for Django tests. The problem is that we are in a closed network...
1

votes
1

answer
35

Views

How should test using tdd repeated behaviors

I have the next code i made a test but now i have a dilema strictly speaking with tdd for add 'this.loadCounter('anotherReq', 'anotherError', differentCallback);' i have to reply the tests only for test the behavior but i not sure if this is necessary. class Statistic extends PureComponent { state...
1

votes
1

answer
192

Views

Typescript: Override static factory method of parent Class in Child method

I'm running into some problems with dependency injection with Typescript. On every Class that I add a factory static method where all dependencies are set. I do this for testing purposes so that I'm still able to use the TDD approach. Now I'm running into some problems with overriding the factory m...
Michel Bitter
1

votes
1

answer
144

Views

How To Spy On An Exported and Mocked Function In Jest

I am trying to mock a module (which has an exported function[and this is also mocked]). I would like to spy on the exported function to check that it was called with something. This is my code... import { addNewPaymentMethod } from '../src/service' jest.mock('../src/service', () => ({ addNewPaymentM...
Exitos
1

votes
4

answer
118

Views

Stateless services vs. HttpClient wanting to be a singleton

Popular opinion seems to be that HttpClient should be used as a singleton: Singleton httpclient vs creating new httpclient request You're using HttpClient wrong and it is destabilizing your software C#: HttpClient should NOT be disposed If nothing else, the aim is to avoid the following: System.Net....
Timo
1

votes
2

answer
91

Views

what is the function of NSObject in StoryBoard / Interface Builder?

I am currently following a video tutorial course about test driven development of iOS in Swift, but when testing Table View in View Controller, I get stuck, since I don't understand why we need NSObject in Interface builder like the picture below: Movie Library Data Service is inheritted NSObject cl...
sarah
1

votes
0

answer
40

Views

The Odin Project TDD solution

I'm doing the Odin Project. I'm learning the TDD bit at the moment. I need help passing the first test for 'helloWorld.' JS file: const helloWorld = function() { return '' } module.exports = helloWorld .spec file: const helloWorld = require('./helloWorld'); describe('Hello World', function() { it('...
j_nguyen
1

votes
1

answer
219

Views

Generate swagger/openapi docs from Mocha/Chai test suite

I want to use Swagger/OpenAPI to standardize documentation efforts. Most of the API's are built with NodeJS and I do integration testing with Mocha & Chai which helps tremendously with quickly making sure the API isn't broken after making changes. From what I understand, using Swagger won't replace...
jtlindsey
1

votes
1

answer
232

Views

mockito unit testing Wanted but not invoked:

I have seen there are similar question already exist in SO , I tried all the solution , but couldn't fix my problem , as I am new to tdd I have a class like this public class AppUpdatesPresenter { public void stopService() { ServiceManager.on().stopService(); } } I have the test class like this @...
mW3
1

votes
1

answer
38

Views

TDD - Where to check if text file format is correct?

I am working on a project that needs to read a text file with a specified format (variable declarations on the first line, assignation to them on the next lines) and then save the information in a class 'A'. I don't get where should I check that the text file has the correct format: in the domain pa...
KissShot94
1

votes
1

answer
298

Views

How to get localStorage working in vue testing

I am trying to test vue components. I have a vue single file component which uses vuex. My states are stored in store.js which makes use of localStorage. However, when I run npm test I get error that reads: WEBPACK Compiled successfully in 9416ms MOCHA Testing... RUNTIME EXCEPTION Exception occur...
Tanmay
1

votes
1

answer
21

Views

Can I make a stub for a range of outcomes? “sinon.stub().callsFake(()=>{})” AssertionError: NaN

From my understanding, a stub is a spy who is forced to take action, such as picking a side(i.e. throw). Can I /or does it makes sense to fake returning a range of number? I am trying to test a 'Loan.prototype.cost', which calls 'Loan.prototype.payment', then does some calculation. In the commented...
David
1

votes
0

answer
53

Views

How to generate coverage report for ES6 code with istanbul

How can I get istanbul to generate coverage with ES6? I'm using jasmine for testing and I can get it to run ES6 code with babel-node node_modules/jasmine/bin/jasmine.js tests/routes.js But I can't use babel-node anywhere with istanbul package.json 'test': 'babel-node node_modules/jasmine/bin/jasmin...
Youngestdj
1

votes
0

answer
34

Views

How do I customise test generators in default Rails 5.2.x?

I am trying to customise which tests are generated by default in a vanilla Rails 5.2.x app. I don't seem to be able to configure the Minitest generators though. The following code in my config/application.rb causes a error minitest [not found] error when I try and generate a model. config.generators...
1

votes
0

answer
49

Views

Test Driven Development for Sequelize models

I am working on a node.js project that uses Sequelize as it's ORM and Postgres as the database. Our Technical Lead requires us to write tests for the models. How do I do that? I have scoured the web but not found how? How can I write tests for Sequelize models with Mocha?
David Essien
1

votes
0

answer
73

Views

How am I suppose to stub a function which is dependent on result of previous function?

I have recently started writing tests and I don't have much experience.If any of the community member could point me in the right direction I would be really thankful. My scenario is simple I am half way through it but unable to solve my exact problem. Below is my code.. return generateServiceToken(...
MQ.
1

votes
2

answer
56

Views

AutoFixture: How to use a common test data set for the generation of different objects?

I would like to test a self written XML parser that takes, well an XML string and returns the model representation of that. T Parse(string content); The issue I am having is regarding the assertion part of my test. Because each time I call Create() it generates new random data, which is not what I w...
Matze
1

votes
3

answer
49

Views

How to unit test a method that is having multiple object creation in switch statement? How to Mock them?

Another question is if there is any better way to write this method? Public decimal CalculateTotalPrice(List items) { decimal totalPrice = 0.m; foreach(Product p in items) { if(p.Offer == '') calc = new DefaultCalc(); else if(p.Offer == 'BuyOneGetOneFree') calc = new BuyOneGetOneFreeCalc(); else if(...
MSR
1

votes
1

answer
32

Views

RhinoMock - AssertWasCalled on same method with different parameter doesn't work

I have this method: public void Handle(ShipmentConfirmedEvent message) { try { var trackingOrderDto = new ShipmentConfirmedDto { AccountId = message.AccountId, FirstName = message.CustomerFirstName, TransactionId = message.TransactionId, Language = message.LanguageCode, ExcludedCommunicationChannels...
Ronco
1

votes
2

answer
56

Views

rspec BDD tests - trying to test index controller method

I have a rails app with a cars model that takes the attribute of 'model'. I'm just trying to run a test to see if the index method in the cars controller will display all the cars. I'm not sure how to go about this. The test currently passes, but it shouldn't as I currently have an empty index metho...
b.herring
1

votes
2

answer
28

Views

spy on argument to class method using sinon

I have a class that I want to spy on to check for the arguments that the method has been called with. class Animal { constructor() { this.animals = []; } add(animal) { this.animals.push(animal); } } My test file looks like this const chai = require('chai'); const sinon = require('sinon'); const Laz...
peter flanagan
1

votes
1

answer
65

Views

What are ways to mock out a struct to get a class under unit tests?

I have a class that I'm trying to get under unit tests. The class exposes a struct as a public property. The struct also has some public methods (that do much more than a method in a struct should). I can't make changes to the struct (I don't own that code and it would be too risky at the moment)....
Ben Joiner
1

votes
1

answer
58

Views

How to cover function using Jest and Axios?

How to cover searchLocation() using Jest and Axios? export const searchLocation = () => { return dispatch => { dispatch(searchLocationStart()); axios.get('https://api.github.com/users/octocat') .then((data) => dispatch(searchLocationSuccess(data.data))) .catch(() => dispatch(searchLocationError)); }...
Patrick
1

votes
1

answer
19

Views

Jest only - addEventListener ~ click assertion

I want to mock a normal dom click as indicated in the Jest docs: test('displays a user after a click', () => { document.body.innerHTML = '' + ' ' + ' ' + ''; // Use jquery to emulate a click on our button $('#button').click(); expect($('#username').text()).toEqual('Johnny Cash - Logged In'); }); M...
Cold Fridge
1

votes
1

answer
220

Views

How do you use debugging to step into a class in a web application from a test project in the same solution?

When using NUnit and the test project, we haven't been able to find a way to step into the class we are testing in a web application. We are using TestDriven.NET add-in for Visual Studio 2008. We are able to hit a breakpoint in the test project, but not step into the web app class that is being test...

View additional questions