tdd

MSTest: how to increase test time

浪尽此生 提交于 2019-12-04 23:50:49
I have one test that needs to work more then 1 minute (VS2008, MSTest, tests are launched from the VisualStudio): const int TestTimeout = 1; [TestMethod] [Timeout(10*60*1000)] // 10 minutes public void Login_ExpirationFail_Test() { IAuthenticationParameters parameters = new AuthenticationParameters(...); LdapAuthentication auth1 = new LdapAuthentication(); IAuthenticationLoginResult res = auth1.Login(parameters); Assert.IsNotNull(res); Assert.IsFalse(string.IsNullOrEmpty(res.SessionId)); const int AdditionalMilisecodns = 400; System.Threading.Thread.Sleep((TestTimeout * 1000 +

Is there a unit-testable way to upload files to ASP.NET WebAPI?

99封情书 提交于 2019-12-04 22:51:56
I'm working in a project that uses the new ASP.NET WebAPI. My current task is to accept an uploaded file. So far, I have used TDD to drive out the WebAPI code, but I've hit a wall with uploading. I'm currently following the advice found at http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2 , but there seems to be no way at all to drive this out of a unit test. In order to get at the file and form data, I have to use MultipartFormDataStreamProvider , which is impossible to mock and/or override. Short of forsaking my TDD approach, what can I do? Here's the code

Unit test wrapper objects?

拟墨画扇 提交于 2019-12-04 22:46:58
I try to use TDD as much as I can. When I do, I stowe all comunication with the outside away in wrapper classes. A few minutes ago, I made a wrapper for the static class Directory , so I can test my other code without talking to the actual file system. But what about unit testing the wrapper itself? Since I use TDD, it nags me that I haven't written tests for it. On the other hand, It is a wrapper and nothing else, so do I really need to? I tend to do the same and not worry about unit testing wrapper classes, as long as I've satisfied myself that they contain the bare minimum amount of code.

Does NUnit's Is.EqualTo not work reliably for classes derived from generic classes?

99封情书 提交于 2019-12-04 20:29:54
问题 Today I ran into the following problem with NUnit. I have a class, that derives from a generic class. I started to do some serialization tests and tested for equality using the Is.EqualTo() function of NUnit. I started to suspect something is wrong, when a test that should have failed passed instead. When I used obj1.Equals(obj2) instead it failed as it should. To investigate I created the following tests: namespace NUnit.Tests { using Framework; public class ThatNUnit { [Test] public void

Testing controller with injected service inside angularJS with jasmine

谁说胖子不能爱 提交于 2019-12-04 20:00:52
问题 I am trying to understand how to test my code with jasmine and angularJS. I wrote a test project with a controller and an injected service. Now i want to test the controller and tried to mock the injected service. But i didn’t found a way to test the function “Arrived” from my controller. Here’s my jsfiddle: http://jsfiddle.net/2fwxS/ controller.js: angular.module('myApp.controllers', []) .controller('MyCtrl', ['$scope', 'MyService', function ($scope, MyService) { $scope.User = {}; $scope

mocha init timeout with mocha-phantomjs

て烟熏妆下的殇ゞ 提交于 2019-12-04 19:10:47
问题 I have the following testrunner.html : <html> <head> <title>Specs</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="/content/css/mocha.css" /> <script> function assert(expr, msg) { if (!expr) throw new Error(msg || 'failed'); } </script> <script src="/client/lib/require.js" type="text/javascript" data-main="/client/specs/_runner.js"></script> </head> <body> <div id="mocha"></div> </body> </html> The _runner.js looks like this: //

Testing Python Scripts

北战南征 提交于 2019-12-04 19:01:49
问题 How do I test the STDOUT output of a Python script with a testing framework like doctest, unittest, nose, etc? For example, say running my script "todo.py --list" should return "take out the garbage". I've read someone who separates out the STDOUT printing part of the script from the part that generates the output to be printed. I'm used to sprinkling print statements all around my shell scripts. Is this simply a TDD unfriendly habit I should break or is there a way to easily test for correct

TDD : Breaks all the existing test cases while refactoring the code

牧云@^-^@ 提交于 2019-12-04 17:24:04
I have started following TDD in my project. But ever since I started it after reading some articles, I am bit confused since the development has slowed down. Whenever I refactor my code, I need to change the existing test cases I have written before because they will start failing. Following is the example: public class SalaryManager { public string CalculateSalaryAndSendMessage(int daysWorked, int monthlySalary) { int salary = 0, tempSalary = 0; if (daysWorked < 15) { tempSalary = (monthlySalary / 30) * daysWorked; salary = tempSalary - 0.1 * tempSalary; } else { tempSalary = (monthlySalary /

Capybara ajax race conditions

丶灬走出姿态 提交于 2019-12-04 17:07:34
I am frequently running into issues in capybara with request tests failing because capybara is not waiting for ajax events to complete before moving on. Google seems to indicate I should be using :resynchronize option for my tests to fix this. But it is not working. To prove this is an issue, failing tests can be fixed by putting a sleep statement after the ajax call. This seems hacky any bad practice as the appropriote delay will vary depending on the speed of the machine running the tests. And picking a suitably large value will seriously slow down running a test suite with lots of ajax

Testing User Model (Devise Authentication) with MiniTest

此生再无相见时 提交于 2019-12-04 17:02:23
I'm trying to test user model, for which I've devise authentication. The problem I'm facing is, 1. Having 'password'/'password_confirmation' fields in fixtures is giving me invalid column 'password'/'password_confirmation' error. If I remove these columns from fixture and add in user_test.rb require 'test_helper' class UserTest < ActiveSupport::TestCase def setup @user = User.new(name: "example user", email: "example@example.com", password: "Test123", work_number: '1234567890', cell_number: '1234567890') end test "should be valid" do assert @user.valid? end test "name should be present" do