unit-testing

Unit-testing a simple collection class

Consider the following class: public class MyIntSet { private List<int> _list = new List<int>(); public void Add(int num) { if (!_list.Contains(num)) _list.Add(num); } public bool Contains(int num) { return _list.Contains(num); } } Following the "only test one thing" principle,...

Testing/troubleshooting tool for network connections?

I am creating a non-blocking IO system for the server side of my project. The actual implementation isn't important (it is Java NIO if you care), but I feel very intimidated by the subtle issues you have to pay close attention to when programming socket communications. My knowledge is lacking in a lot of areas, so I can't even conceive...

Strange behavior in the "Verify" method in Moq

In the following code, Test1 succeeds but Test2 fails: protected Mock<IMyInterface> MyMock { get; set; } [SetUp] public virtual void Initialize() { MyMock = new Mock<IMyInterface>(); } [Test] void Test1() { // ... code that causes IMyIntervace.myMethod to be called once MyMock.Verify(x=> x.myMethod(), Times.Once()); } [...

should i use the built in utils in vs2008 for unit testing ?

i want to start writing unit tests for my project, what add ons if needed should i install, what abilities do i get by default? ...

Unit Testing ASP.net Web Site Project code stored in App_Code

I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code behind code files (including Linq2Sql stuff, data contexts, business logic, extension methods, etc) are located in the App_Code folder. I am interested in introducing Unit Testing (using nunit) in at least some sections of the project moving forward. Any Unit T...

testing REST with shoulda and factory_girl - destroy

Hi, i'm developing test for REST using shoulda and factory_girl. Code below context "on :delete to :destroy" do setup do @controller = NewsArticlesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @news_article = Factory.create(:news_article) en...

Is it a code smell for one method to depend on another?

I am refactoring a class so that the code is testable (using NUnit and RhinoMocks as testing and isolations frameworks) and have found that I have found myself with a method is dependent on another (i.e. it depends on something which is created by that other method). Something like the following: public class Impersonator { private ...

How to distribute and execute platform-specific unit tests?

We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests that should pass on platforms A, B, C and tests that pass on B and D. What is the bes...

NUnit Categories in combination?

In my NUnit testfixtrues i have something along the lines of [Test,Category("catA")] public void test1 { // } [Test,Category("catB")] public void test2 { // } [Test,Category("catA")] [Test,Category("catB")] public void test3 { // } Now in the NUnit gui i want to be able to select catA and catB and run the tests where cat...

NUnit Conditional Teardown?

Is there a way to do a conditional TearDown in NUnit? I have a TestFixture which has a need to run cleanup code for just a few tests, and I don't really want to: Run the TearDown method on every test Create a private helper method and call it from the tests requiring cleanup if I can avoid it ...

How far should I go with unit testing?

I'm trying to unit test in a personal PHP project like a good little programmer, and I'd like to do it correctly. From what I hear what you're supposed to test is just the public interface of a method, but I was wondering if that would still apply to below. I have a method that generates a password reset token in the event that a user f...

unit testing a java constructor that exits the application

Duplicate: Java: How to test methods that call System.exit()? Hello, I am having a bit of a trouble designing a unit test for a method that exits the application by calling system.exit(). Actually this is the constructor of a class which tests some conditions and decides to exit the application. So it is this particular eventuallity th...

Is it possible to Mock a Database Transaction parameter?

I'm trying to unit-test my implementation of an interface, and I'm having a little difficulty successfully mocking out a SqlTransaction parameter to one of the interface methods. Here's what the interface, and method under test that I'm interested in look like.. public class MyInterface { void MyMethod(SqlTransaction SharedTransact...

Code works but test fails

I have a test that's failing even though the operation actually works when I test it in the browser. Something wrong with my test, looks like. I'm using Shoulda and fixtures. require 'test_helper' class AddressesControllerTest < ActionController::TestCase context 'on PUT to :update' do setup do put(:update, { :id...

How do I do dependency injection and mocks in erlang?

Hi. When writing code in Java, it is very helpful to embrace composition and dependency injection to make it possible and easy to do pure unit testing by mocking collaborating objects. I find that doing the same in Erlang is less straightforward and makes for dirtier code. That's likely to be my fault, as I'm quite new to Erlang and q...

Using Request.Files.Count with TestControllerBuilder from MvcContrib?

I have a controller action in ASP.NET MVC that handles uploaded files. However, it seems there is no way to call Request.Files.Count while using MvcContrib's TestControllerBuilder. I know I can work around this by abstracting Request.Files. My questions are: Is it indeed the case that there is no direct way to call Request.Files.Count...

"Short circuiting" void methods with Moq?

Hi, my team has made the decision recently to use Moq as our mocking framework for its tremendous flexibility and highly readable syntax. As we're new to it, I'm stumbling on what appears to be simple questions--searches (here, Google, etc.) find plenty of discussions on other nuances of Moq, but not necessarily what I'm after, and the ...

DbUnit how to guard against multiple tests running at the same time?

I am working on a test environment for a project, and am looking into using DbUnit.NET to do a lot of the database interaction testing. I do have one very big question though: We are running against Oracle, and setting up a seperate test DB instance for every developer really isn't feasible (especially since we only have 1 DBA who is al...

Why is this expectation failing?

I'm setting up some RhinoMock tests but I can't work out why my expectations are failing. Here are the class/ interface I'm testing: public class LogOn { public virtual ILogOn View { get; set; } public virtual IDataProvider DataProvider { get; set; } public void SetUp(ILogOn view) { this.View = view; this.DataProvider = ... //u...

How can I create unit tests involving collections in c#?

I have a number of methods in C# which return various collections which I wish to test. I would like to use as few test APIs as possible - performance is not important. A typical example is: HashSet<string> actualSet = MyCreateSet(); string[] expectedArray = new string[]{"a", "c", "b"}; MyAssertAreEqual(expectedArray, actualSet); //.....