tdd

testing an internal class

有些话、适合烂在心里 提交于 2019-11-28 11:33:26
how to write unit tests to internal classes ??? You write tests which specify the behaviour of the top-level class' external interface. Whether that class uses internal classes to implement that behaviour or not, is an implementation detail of the class, and the tests don't need to know anything about it. If the internal class cannot be adequately tested through the top-level class' interface, then it's usually best to move the internal class out and test it directly as a new top-level class. Wanting to test internal classes is a code smell that the internal class might be significant enough

Is it bad practice to run tests on a database instead of on fake repositories?

ε祈祈猫儿з 提交于 2019-11-28 09:54:15
I know what the advantages are and I use fake data when I am working with more complex systems. What if I am developing something simple and I can easily set up my environment in a real database and the data being accessed is so small that the access time is not a factor, and I am only running a few tests. Is it still important to create fake data or can I forget the extra coding and skip right to the real thing? When I said real database I do not mean a production database, I mean a test database, but using a real live DBMS and the same schema as the real database. Uncle Bob The reasons to

Which is an acceptable approach for testing commands in Laravel 5.2 with PHPUnit?

我只是一个虾纸丫 提交于 2019-11-28 09:36:11
问题 I'm trying to write test cases for Commands in PHPUnit, without much success. At this point I've tried many things, being probably this post the closest approach I found for my purpose. Still, I'm struggling a lot to get this working. Follows an example output for you: alariva@trinsic ~/timegrid.io/app $ phpunit --filter=SendBusinessReportTest PHP Warning: The use statement with non-compound name 'Artisan' has no effect in /home/alariva/timegrid.io/app/tests/unit/Console/Commands

Check method call on model using MiniTest

前提是你 提交于 2019-11-28 08:53:45
问题 If I was using RSpec I could test if a method is being called like so: expect(obj).to receive(:method) What is the equivalent in MiniTest? I have a model, Post , which has a before_validation callback which runs a method create_slug . In my test test/models/post_test.rb I want to ensure that the create_slug method is being called when calling post.save . The Minitest::Spec documentation says that I can use a method must_send to check if a method is called. However, when I try @post.must_send

What test methods do you use for developing websites?

安稳与你 提交于 2019-11-28 08:43:45
There are a lot of testing methods out there i.e. blackbox , graybox , unit , functional , regression etc. Obviously, a project cannot take on all testing methods. So I asked this question to gain an idea of what test methods to use and why should I use them. You can answer in the following format: Test Method - what you use it on e.g. Unit Testing - I use it for ...(blah, blah) Regression Testing - I use it for ...(blah, blah) I was asked to engage into TDD and of course I had to research testing methods. But there is a whole plethora of them and I don't know what to use (because they all

What is the best practice when it comes to testing “infinite loops”?

南笙酒味 提交于 2019-11-28 08:09:21
My basic logic is to have an infinite loop running somewhere and test it as best as possible. The reason for having an infinite loop is not important (main loop for games, daemon-like logic...) and I'm more asking about best practices regarding a situation like that. Let's take this code for example: module Blah extend self def run some_initializer_method loop do some_other_method yet_another_method end end end I want to test the method Blah.run using Rspec (also I use RR , but plain rspec would be an acceptable answer). I figure the best way to do it would be to decompose a bit more, like

How to exclude certain tests in the Visual Studio Test Runner?

浪尽此生 提交于 2019-11-28 08:03:53
I have attributes on certain tests that I ideally don't want to run on every build. Most of my tests are normal unit tests and I do want them to run on every build. So: how can I exclude a test by category or project type? For example, I'd like to exclude CodedUItests : [CodedUITest] public class SearchViewTests ...or exclude tests in a given TestCategory : [TestMethod] [TestCategory("Database Integration")] public void ContactRepositoryGetByIdWithIdExpectCorrectContact() I particularly want to exclude the coded UI tests as they disrupt my ability to continue working, whereas all the other

Jest. How to mock console when it is used by a third-party-library?

馋奶兔 提交于 2019-11-28 07:08:58
I am trying to mock console.warn/error but i can't. I use a third-party-library which calls console.warn inside it. I need to test was it called or wasn't. In my test case i was trying to stub console.warn but it didn't help. After that i was trying to mock console manually it didn't work out either. console.warn = jest.fn(); testSchema('/app/components/Users/UserItem/UserItemContainer.js'); expect(console.warn).toBeCalled(); didn't work console.warn = jest.fn(); testSchema('/app/components/Users/UserItem/UserItemContainer.js'); console.warn('error'); expect(console.warn).toBeCalled(); did

Looking for papers/studies on TDD effectivness [closed]

主宰稳场 提交于 2019-11-28 05:52:29
I'm looking for research papers or studies made on Unit Testing and TDD effectiveness. Points of interest: Does TDD reduce Development time? Does overall development cost reduced as well? Is the result product more stable? Microsoft Research: Realizing quality improvement through test driven development: results and experiences of four industrial teams StudiesOfTestDrivenDevelopment has a summary and more links. An article on infoQ: Empirical Studies Show Test Driven Development Improves Quality . And a link to the Realizing quality improvement through TDD study . "TDD seems to be applicable

Let method take any data type in c#

旧巷老猫 提交于 2019-11-28 04:59:12
I have a lot of unit tests that pretty much tests the same behavior. However, data type changes. I am trying to create a generic method that can take any data type. I tried making my input parameter var but that's not allowed. Also, looked into c# generics but that usually deals with a list. You could make the parameter an object : public void DoSomething(object arg) { //... Or you could do what I prefer and make a generic method: public void DoSomething<T>(T arg) { //... The generic approach has two major advantages, and I'll give examples of why they're useful: Even though you don't