tdd

NUnit Test - Looping - C#

假如想象 提交于 2019-12-11 05:15:36
问题 I am new to TDD and trying to solve a problem. In my task, I have to read a bunch of strings from console and add them to a list of string type. In my test method, I have written a for loop to read strings and passing to a method to add. I don't know how to test this process, a bit confused. Any help will be appreciated. Thanks. Loop in the test method. for(int i=0;i<robot.noOfCommands;i++) { robot.readCommand(Console.ReadLine()); } I am writing code in C#.Net 回答1: Unit tests should never

Why are mocking test frameworks helpful?

血红的双手。 提交于 2019-12-11 04:57:26
问题 It seems like all of the Mockito examples I have looked at, "fake" the behavior of the object they are testing. If I have an object that has a the method: public int add(int a, int b) {return a+b} I would simply use JUnit to assert whether two integers passed in would result in the correct output. With all of the examples I've seen with Mockito, people are doing things like when.Object.add(2,3).thenReturn(5) . What's the point of using this testing framework, if all you're doing is telling

How to TDD functionality in a base mixin class from one of many leaf classes?

∥☆過路亽.° 提交于 2019-12-11 04:41:28
问题 following on from this question (Developing to an interface with TDD), I'm still having some issues. I test-drove two classes into existence, both of which ended up shared some identical functionality. I refactored a common base class into existence, and all the tests still passed. So far, so tdd-tastic. I needed a third class to implement the base class, so copied some tests into a new fixture and made each one compile and go green in turn, until I had a fully-functional third class. This

Unit testing: Am I doing right when using another method in unit testing a method?

假装没事ソ 提交于 2019-12-11 04:39:52
问题 To my best knowledge, unit testing should be done on each public API separately. But, I have been experiencing with a situation in which I have not found out a clear way to unit test each API independently as shown in the following example: class MyStorage { private: std::vector<int> int_vec_; public: bool insert_int(int value); int get_value_at(int idx); } I used GooogleTest framework and wrote unit tests as follows: int int_tenth(int x) { return x * 10; } TEST_F(MyStorageTest, insert_int) {

What is the best way to deal with conversion methods when doing TDD?

◇◆丶佛笑我妖孽 提交于 2019-12-11 04:24:11
问题 What is the best practice is for dealing with conversions that occur in methods when trying to do test driven development? Is it to create static utility methods that perform the conversions and then write unit tests on those utility methods? I feel like the problem with that is when you write tests against the parent method that calls this utility method, you have to account for the conversion occurs, since most mocking frameworks do not mock utility methods. Therefore, writing verification

Should I use TDD to design my clients as well as my libraries?

点点圈 提交于 2019-12-11 03:28:23
问题 Assuming you create a library to do some calculations, you use TDD to build it without problems, right? Now you must implement the code that actually uses this library. The client could be a Java Servlet or a CLI Program, for example. Must this client code be built using the TDD concept? You write tests for these clients? Is TDD solely about design of the library, or do I need to worry about the client code? 回答1: I will answer your question more directly below after I give some info on TDD.

PHPUnit TDD, PHP Fatal error: Call to undefined method

拟墨画扇 提交于 2019-12-11 03:23:20
问题 I'm starting a TDD project using PHPUnit and something really bugs me. It seem that all test can't be run as long as all classes and methods will not be implemented. How can I do to make the test continue event if a class or a method is not yet implemented ? Thanks. Edit: "Isn't the point of TDD that your testsuite fails while writing tests?" Yes, of course, but I want to have a global sight of the project. Let say we've written 1000 test, and the first one that is run makes a fatal error.

How to test internal functions, which are needed for internal purposes, using Jasmine

我的未来我决定 提交于 2019-12-11 03:17:42
问题 (function(window,document){ var _trimString = function( string ){ var trimString; trimString = string.replace(/^\s+|\s+$/g,''); return trimString }; var displayCorrectText = function( incorrecttext ){ correctText = "."+incorrecttext; document.write( correctText ); } var Circular = function(){}; Circular.prototype.init = function( string ){ displayCorrectText( _trimString( string ) ); }; var circular = new Circular(); window.circular = circular; })(window,document); circular.init('asd.asd'); I

Laravel 5.1 + PHPunit - API test returns always invalid argument error foreach

只谈情不闲聊 提交于 2019-12-11 03:15:00
问题 I've upgraded from Laravel 5.0 to 5.1 Test suite works fine and I can run the phpunit command. But, when I'm start to test with the api test, I always get a foreach error. class ExampleTest extends TestCase { public function testLoginCredentials() { $this->post('/srv/plc/auth/login', ['data' => 'some data']) ->seeJson([ 'authorized' => true, ]); } } Above looks like the documentation: http://laravel.com/docs/5.1/testing#testing-json-apis If I run my test via phpunit, I get the following error

Use a factory's sequence to generate unique phone numbers

霸气de小男生 提交于 2019-12-11 02:59:41
问题 I'm new to TDD, RSpec and factories, and trying to understand how to test that each User's phone number attribute is unique. To do so, I'm trying to use a sequence in my User factory. I'm not having much luck with the following: FactoryGirl.define do factory :user do number = 123456789 sequence(:phone_number) {|n| (number + n).to_s } end end Any thoughts on the best way to accomplish this? Also, what kind of test would make sense for something like this where ultimately I would want to add