tdd

Unit Testing Example with OCUnit

a 夏天 提交于 2019-11-29 18:49:32
I'm really struggling to understand unit testing. I do understand the importance of TDD, but all the examples of unit testing I read about seem to be extremely simple and trivial. For example, testing to make sure a property is set or if memory is allocated to an array. Why? If I code out ..alloc] init] , do I really need to make sure it works? I'm new to development so I'm sure I'm missing something here, especially with all the craze surrounding TDD. I think my main issue is I can't find any practical examples. Here is a method setReminderId that seems to be a good candidate for testing.

How do I write unit tests in PHP? [closed]

十年热恋 提交于 2019-11-29 18:44:20
I've read everywhere about how great they are, but for some reason I can't seem to figure out how exactly I'm supposed to test something. Could someone perhaps post a piece of example code and how they would test it? If it's not too much trouble :) There is a 3rd "framework", which is by far easier to learn - even easier than Simple Test, it's called phpt. A primer can be found here: http://qa.php.net/write-test.php Edit: Just saw your request for sample code. Let's assume you have the following function in a file called lib.php : <?php function foo($bar) { return $bar; } ?> Really simple and

Unit test adoption [closed]

左心房为你撑大大i 提交于 2019-11-29 18:35:21
We have tried to introduce unit testing to our current project but it doesn't seem to be working. The extra code seems to have become a maintenance headache as when our internal Framework changes we have to go around and fix any unit tests that hang off it. We have an abstract base class for unit testing our controllers that acts as a template calling into the child classes' abstract method implementations i.e. Framework calls Initialize so our controller classes all have their own Initialize method. I used to be an advocate of unit testing but it doesn't seem to be working on our current

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

删除回忆录丶 提交于 2019-11-29 15:32:37
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/SendBusinessReportTest.php on line 4 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2. PHPUnit_TextUI

Get Stored Procedure from Data Context : Linq to SQl

こ雲淡風輕ζ 提交于 2019-11-29 15:10:31
I have a stored procedure named ParseXML in SQL Server. I have a repository pattern using LINQ to SQL. I need to call the stored procedure from within the repository layer. Unlike GetTable method, we don’t have a GetStoredProcedure method for data context. How can we call the stored procedure in such a scenario? Dbml Code [global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.ParseXML")] public ISingleResult<ParseXMLResult> ParseXML([global::System.Data.Linq.Mapping.ParameterAttribute(Name="InputXML", DbType="Xml")] System.Xml.Linq.XElement inputXML) { IExecuteResult result = this

Check method call on model using MiniTest

馋奶兔 提交于 2019-11-29 14:46:06
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 :create_slug I receive the following error: NoMethodError: undefined method `must_send' for #<Post

How do I run a function before each test when using qUnit?

若如初见. 提交于 2019-11-29 14:29:37
问题 What is the equivalent of nUnits [SetUp] attribute for qUnit? 回答1: Registering a QUnit Callback var mySetupFunc(details){/* setup code */} QUnit.testStart(mySetupFunc); Callback Details As of QUnit version 1.10.0pre-A, each registered callback will receive a hash as the first (and only) parameter. I've named mine 'details' in the example above. The contents of the hash vary by callback. Here's a list of information in each hash. begin (start of all tests) {} /* empty hash */ done (end of all

View Controller TDD

我们两清 提交于 2019-11-29 13:53:11
问题 I am trying to add some unit tests to my project to test view controllers. However I seem to be having problems with seemingly simple things. I have created a sample project which I will refer to. https://github.com/pangers/ViewControllerTesting The sample contains a UINavigationController as the initial view controller. The root view controller of the UINavigationController is FirstViewController. There is a button on FirstViewController that segues to SecondViewController. In

What book on TDD for C# with treatment of Mocks

我是研究僧i 提交于 2019-11-29 11:23:46
Can you recoment a book on on Unit Testing and TDD for C# with at least some treatment of Mock Objects? I have seen this question but it does not seem to mention mocking. The Art of Unit Testing: With Examples in .NET by Roy Osherove ( Amazon Page , Official Site ) sounds like what you're looking for. He devotes one chapter introducing the concepts of stub and mock objects (using a "roll-your-own" approach), and then a second chapter on using mock object frameworks, particularly Rhino Mocks . There is somewhat less emphasis on Test-Driven Development, but there is quite a lot of information

How to test if a List<? extends Object> is an UnmodifableList?

感情迁移 提交于 2019-11-29 11:11:09
问题 I'm looking for a way to test if some given List is an unmodifiable one. I have an object that has a List<NoMatter> , in order to offer methods such as addNoMatter(NoMatter nm) instead of allowing the API client to simply do .getNoMatters().add(nm); I always return an unmodifiable version of this list, so the client is still able to have the list. I do it as follows: public List<NoMatter> getNoMatters() { return Collections.unmodifiableList(this.noMatters); } The problem is that when I'm