tdd

How to do TDD and unit testing in powershell?

隐身守侯 提交于 2019-11-26 22:20:36
问题 With MS ramming powershell into all new server products, I'm starting to (reluctantly) think I need to take it seriously. Part of "taking it seriously" is TDD. Have you found good methods to unit test power shell scripts? I've found samples of mocking from Mr Geek Noise - but I'd really like something like RhinoMocks. Brian Hartsock has a sample of running tests on powershell strings from MS Test. A little hacky, but it seems to work. What I want is a Powershell TDD experience that is as

C# “internal” access modifier when doing unit testing

我的未来我决定 提交于 2019-11-26 21:13:57
I'm new in unit testing and I'm trying to figure out if I should start using more of 'internal' access modifier. I know that if we use 'internal' and set the assembly variable 'InternalsVisibleTo', we can test functions that we don't want to declare public from the testing project. This makes me think that I should just always use 'internal' because at least each project (should?) has it's own testing project. Can you guys tell me a reason why I shouldn't do this? When should I use 'private'? EricSchaefer Internal classes need to be tested and there is an assemby attribute: using System

How do I run unittest on a Tkinter app?

此生再无相见时 提交于 2019-11-26 19:59:38
问题 I've just begun learning about TDD, and I'm developing a program using a Tkinter GUI. The only problem is that once the .mainloop() method is called, the test suite hangs until the window is closed. Here is an example of my code: # server.py import Tkinter as tk class Server(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.mainloop() # test.py import unittest import server class ServerTestCase(unittest.TestCase): def testClassSetup(self): server.Server() # and of course I can't call any

What do programmers mean when they say, “Code against an interface, not an object.”?

淺唱寂寞╮ 提交于 2019-11-26 19:35:27
I've started the very long and arduous quest to learn and apply TDD to my workflow. I'm under the impression that TDD fits in very well with IoC principles. After browsing some of TDD tagged questions here in SO, I read it's a good idea to program against interfaces, not objects. Can you provide simple code examples of what this is, and how to apply it in real use cases? Simple examples is key for me (and other people wanting to learn) to grasp the concepts. Thanks so much. Consider: class MyClass { //Implementation public void Foo() {} } class SomethingYouWantToTest { public bool MyMethod

Random data in Unit Tests?

你离开我真会死。 提交于 2019-11-26 19:31:45
I have a coworker who writes unit tests for objects which fill their fields with random data. His reason is that it gives a wider range of testing, since it will test a lot of different values, whereas a normal test only uses a single static value. I've given him a number of different reasons against this, the main ones being: random values means the test isn't truly repeatable (which also means that if the test can randomly fail, it can do so on the build server and break the build) if it's a random value and the test fails, we need to a) fix the object and b) force ourselves to test for that

test a file upload using rspec - rails

拟墨画扇 提交于 2019-11-26 19:20:17
I want to test a file upload in rails, but am not sure how to do this. Here is the controller code: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid = session[:session_id] puts "\n\nSession_id:\n#{sessid}\n" #Generate a random string chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(5) { |i| newpass << chars[rand(chars.size-1)] } #Get the original file name upload=params[:upload] name = upload['datafile'].original_filename @license.format = File.extname(name) #calculate license ID and location @license

Bash and Test-Driven Development

江枫思渺然 提交于 2019-11-26 19:17:37
问题 When writing more than a trivial script in bash, I often wonder how to make the code testable. It is typically hard to write tests for bash code, due to the fact that it is low on functions that take a value and return a value, and high on functions that check and set some aspect in the environment, modify the file-system, invoke a program, etc. - functions that depend on the environment or have side effects. Thus the setup and test code become much more complicated than the code they test.

Best way to create a test database and load fixtures on Symfony 2 WebTestCase?

冷暖自知 提交于 2019-11-26 19:05:02
问题 I have a WebTestCase that executes some basic routes in my application. I want to, on the setUp method of PHPUnit, create a test database identical to my main database, and load fixtures into it. I'm currently doing some workaround and executing some console commands, something like this: class FixturesWebTestCase extends WebTestCase { protected static $application; protected function setUp() { self::runCommand('doctrine:database:create'); self::runCommand('doctrine:schema:update --force');

How to start unit testing or TDD?

孤街浪徒 提交于 2019-11-26 18:50:52
问题 I read a lot of posts that convinced me I should start writing unit test, I also started to use dependency injection (Unity) for the sake of easier mocking, but I'm still not quite sure on what stage I should start writing the unit tests and mocks, and how or where to start. Would the preferred way be writing the unit tests before the methods as described in the TDD methodology? Is there any different methodology or manner for unit testing? 回答1: Test first / test after: It should be noted

Unit tests on MVC validation

旧街凉风 提交于 2019-11-26 18:49:47
问题 How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1? Some code to illustrate. First, the action: [HttpPost] public ActionResult Index(BlogPost b) { if(ModelState.IsValid) { _blogService.Insert(b); return(View("Success", b)); } return View(b); } And here's a failing unit test that I think should be passing but isn't (using MbUnit & Moq): [Test] public void When_processing