1
голосов
5ответов
105 просмотров

Is there a way to tell whether a function is getting executed in a unittest?

I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that po...

4
голосов
1ответов
7518 просмотров

Rails Test & Mocha: How to stub specific model - conditional any_instance?

I want to stub just a specific model, but not only a specific object and not every instance E.g. Given class 'Person' with attributes 'name' (string) and 'cool' (boolean). We have two models: person_bill: name: bill cool: false person_steve: name: steve cool: false Now I want to...

4
голосов
3ответов
125 просмотров

Should you have an interface for all objects/classes

As part of process improvements we are trying to ensure that all our projects have suitable unit tests, as there is a bit of education required in house I am trying ascertain what exactly is the best way to ensure we are making our classes as 'testable' as possible. I suspect that we will start...

3
голосов
2ответов
131 просмотров

iPhone development Unit Testing Linking Problem

I've been trying to determine the cause of this error for days now. Tried doing simple projects by I could not get the unit tests to work? Does anyone know how to solve this problem? Building target “ChildTests” of project “Person” with configuration “Debug” — (2 errors) Linking /Use...

2
голосов
2ответов
1537 просмотров

Is log4net killing my WCF unit tests?

I have three projects in my solution: A WCF web service which provides functionality I want to test A Web Application which calls that web service A test project which runs tests on the service. The web service and the web application both use log4net with separate configuration files and thi...

0
голосов
6ответов
1506 просмотров

Unit Testing & Primary Keys

I am new to Unit Testing and think I might have dug myself into a corner. In your Unit Tests, what is the better way to handle primary keys? Hopefully an example will paint some context. If create several instances of an object (Lets' say Person). My unit test is to test the correct relations...

5
голосов
3ответов
1554 просмотров

Testing Finalizers and IDisposable

The question is how can I test the fact that object disposes resources when finalise is called. The code for the class: public class TestClass : IDisposable { public bool HasBeenDisposed {get; private set; } public void Dispose() { HasBeenDisposed = true; } ~TestClass(...

3
голосов
4ответов
244 просмотров

Does a Unittest has to have an Assertion like "assertEquals(..)"

I have a little JUnit-Test that export an Object to the FileSystem. In the first place my test looked like this public void exportTest { //...creating a list with some objects to export... JAXBService service = new JAXBService(); service.exportList(list, "output.xml"); } Usually m...

6
голосов
1ответов
1128 просмотров

iPhone: Application Testing and Core Location

I'm trying to implement Application Tests as described here. So far, so good, but i fail to test, for instance, the location of the device using Core Location. I have added the appropriate Framework to the Target, and have initiated the update of location, but i have no clue of how to wait for th...

22
голосов
4ответов
3543 просмотров

How to write tests without so many mocks?

I am a heavy advocate of proper Test Driven Design or Behavior Driven Design and I love writing tests. However, I keep coding myself into a corner where I need to use 3-5 mocks in a particular test case for a single class. No matter which way I start, top down or bottom up I end up with a design ...

1
голосов
3ответов
170 просмотров

What is the name of the pattern?

I often design system where I have a class in my system that has a bunch of protected methods. The protected methods are that because they should be accessible to specializations, and as such, I consider the protected methods to be a contract between my general class and any specialized classes. ...

49
голосов
9ответов
28163 просмотров

Why is it so bad to mock classes?

I recently discussed with a colleague about mocking. He said that mocking classes is very bad and should not be done, only in few cases. He says that only interfaces should be mocked, otherwise it's an architecture fault. I wonder why this statement (I fully trust him) is so correct? I don't kn...

1
голосов
1ответов
152 просмотров

UnitTest frameworks for AS2?

I have just tried out ASUnit and it wasn't a success, so I'm looking for something simpler, no need for fancy UI. trace output is fine. ASUnit was not a success because it for some strange reason generated AllTests.as files in all subdirs of /Applications. I can't figure out how to stop this fro...

1
голосов
3ответов
939 просмотров

Source code is in JDK 1.4 and JUnit test cases in JDK 1.5

I am working on a project that is using JDK 1.4 and I am planning to write JUnit test cases in JDK 1.5 for several reasons like: I wanna explore JDK 1.5 to use Mocking frameworks more efficiently. Is it a good idea to do so?? (I've created two projects in Eclipse and am trying this)

27
голосов
5ответов
10068 просмотров

How do I test for multiple exceptions with PHPUnit?

When testing for exceptions with PHPUnit, what is the best way to require that every statement or assertion must throw an exception in order for the test to pass? I basically want to do something like this: public function testExceptions() { $this->setExpectedException('Exception'); ...

11
голосов
8ответов
12587 просмотров

Is it possible to ignore certain unit tests?

I'm currently working on a project which uses JUnit4 extensively throughout all the modules. We're using Maven2 to build the project and Hudson for continuous integration. The project is built and run under Java 1.5. We've recently added quite a large raft of unit tests which are needed at times...

4
голосов
1ответов
5453 просмотров

Run Jettys ServletTester within JUnit test

I'm trying to run Jettys ServletTester in my JUnit test. I created a simple HelloServlet first to test the setup, but I get an IllegalAccessException when I try to request the servlet. Here is what I have so far: My unit test @Before public void setUp() throws Exception { tester = new Servl...

1
голосов
3ответов
980 просмотров

how to mock a parametrized constructor?

I've the following class. It has the code to connect to SAP in its constructor. There is an abstract method(the subclasses define the implementation) which I want to mock. public abstract class BapiExecutor { ... public BapiExecutor(final SapConnectionInfo connectionInfo) ...

1
голосов
3ответов
1380 просмотров

NUnit. How to automatically generate tests?

Is there any software that simplifies creation of tests? Most of the contents of tests is pretty repetitive, so I thought someone might have automated this.

1
голосов
1ответов
1104 просмотров

.NET Conditional Compiler Symbols and Unit Test Libraries

My team has a set of unit test libraries that run against our application code - unfortunately they are throwing (unexpected) exceptions. The reason for this is that our logging code is being called and the objects aren't setup. The logging code is executed via a method attribute we have setup us...

15
голосов
5ответов
2422 просмотров

How do I go about setting up a TDD development process with Google App Engine?

I'm primarily a Ruby guy, but lately I've been working on a lot of Python stuff, in particular, App Engine code. In Ruby, I'd use automated continuous integration (autotest), code coverage tools (rcov), static analysis (reek), and mutation testing (heckle) in my development process, but I'm not ...

0
голосов
3ответов
781 просмотров

unit testing/ mocking static event handlers, what are the available options?

Im fully aware of the "problem" with static event handlers from a GC perspective so i'm not looking for advice on "DONT use static events" or anything like that, in my scenario this isnt a concern. I have a static class which has an event declared public static event EventHandler<MyEventArgs...

3
голосов
2ответов
369 просмотров

Visual Studio "Run a method" vs "Utility tests"

I use XUnit and Resharper to run my tests. In a given project I usually have a few utility tests which are not really tests but exist purely so I can execute a bit of code easily. For example, I have a test which outputs my NHibernate mappings (I use Fluent NHibernate) to a temporary directory. I...

1
голосов
3ответов
476 просмотров

Mocking inter-method dependencies

I've recently started using mock objects in my tests, but I'm still very inexperienced with them and unsure of how to use them in some cases. At the moment I'm struggling with how to mock inter-method dependencies (calling method A has an effect on the results of method B), and whether it should ...

1
голосов
1ответов
173 просмотров

QUnitAdaptor for JSTestDriver passing failed test

Using QUnitAdaptor to test my QUnit tests, it actually passed a test which is supposed to fail: test("very simple test", function() { var somevar = true; equals(somevar, false, "test"); }); The above test passed when I ran it after capturing browser programmatically. Has anyone experienced th...

1
голосов
2ответов
596 просмотров

VS2008 Unit Tests: How to include a message with a "success"

Using Visual Studio 2008 for a unit test, one of the unit tests has to do with a basic performance smoke test to make sure additional code doesn't slow down a heavily-used method too badly. Obviously, I want this to fail when the "# per second" falls below a certain value, and of course it displ...

1
голосов
3ответов
185 просмотров

Unit testing a method called during initialization?

I have a class like the following: class Positive(object): def __init__(self, item): self._validate_item(item) self.item = item def _validate_item(self, item): if item <= 0: raise ValueError("item should be positive.") I'd like to write a unit te...

2
голосов
4ответов
674 просмотров

How to test the function behavior in unit test?

If a function just calls another function or performs actions. How do I test it? Currently, I enforce all the functions should return a value so that I could assert the function return values. However, I think this approach mass up the API because in the production code. I don't need those functi...

3
голосов
4ответов
1391 просмотров

Testing MVC Controller Action HttpAcceptAttribute Verbs

What is the best way to unit test the controller action HttpAcceptAttribute verbs? So far I have the following but it's so ugly even a mother couldn't love it and not very flexible. Is there a better way? [Fact] // using xUnit, mocking controller in class public void FilterControllerTestRemoveF...

15
голосов
12ответов
4287 просмотров

How to unit test private methods in BDD / TDD?

I am trying to program according to Behavior Driven Development, which states that no line of code should be written without writing failing unit test first. My question is, how to use BDD with private methods? How can I unit test private methods? Is there better solution than: - making priva...