unit-testing

Python unittest: how to run only part of a test file ?

Hi, I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class. Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn't run (the best way woul...

When to use @Override in java

Possible Duplicate: When do you use Javas @Override annotation and why? From the javadoc for the @Override annotation: Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, com...

What does it mean to unit test an MVC view?

On a new ASP.NET MVC application we are following a TDD approach, using NUnit for unit testing and Unity for Dependancy Injection. Our views are being made as "dumb" as possible by adjusting our models to supply data in the most appropriate fashion for our views. Is there a merit in unit testing our views? If so - how? ...

Is there a way to override a Perl "use constant" in your unit testing?

I have a Perl module that I have declared some constants: use constant BASE_PATH => "/data/monitor/"; In live operation the constant will never change but I wish to be able to modify it in my unit tests, e.g. to set it to ~/project/testdata/. Is there a way do do this without having to use "non-constants"? Could I possibly use Test:...

Implementing NHibernate Unit Test to Generate Schema with VB.NET/MBUnit

Hi, I'm trying to implement unit tests for my NHibernate data access layer. The first test, which I drew from an example I found on the web (http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx), is just trying to recreate the database using my domain classes/mappings. I've been...

Excluding code from test coverage

Wherever possible I use TDD: I mock out my interfaces I use IOC so my mocked ojbects can be injected I ensure my tests run and that the coverage increases and I am happy. then... I create derived classes that actually do stuff, like going to a database, or writing to a message queue etc. This is where code coverage decreases - an...

AssertWasCalled in rhino mocks

I have an object under test that makes a fairly complicated call to a data access object. IT looks something like object.DoSomething(somestring,someObject,someOtherObject,someOtherOtherObject) In my test structure I have a mocked version of object and I want to test that Dosomething got called with somestring == "value1" and someObjec...

How to separate unit test methods?

Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else { // second case } } Which is your preferred unit test organization method? Option 1: void MethodTest(){ // test first case // test second case } or Option 2: void MethodTestFirstCase(){ // test first case ...

why unit test for exceptions?

Hi I am wondering why should you unit test exceptions? Like I thought you should not be testing code you did not write. In a sense to me you're not really writing the exception. Sure you put it in a try/catch but should you not assume that the try catch will work and you will catch that exception. Like for instance I have some GetUser...

Should the JUnit message state the condition of success or failure?

I can write an assertion message one of two ways. Stating success: assertEquals( "objects should be identical", expected, actual ); Or stating the condition of being broken: assertEquals( "objects aren't identical", expected, actual ); Is there a standard for this in JUnit specifically? If not, what are the arguments for each sid...

Running PHP Zend Test in Eclipse

Is it possible to run PHP Zend test cases (those that extend Zend_Test_PHPUnit_ControllerTestCase, etc.) through Eclipse PDT? I would like to be able to run them in a similar fashion as you run JUnit tests in Eclipse, by right-clicking the test file and selecting "Run as a JUnit test case." I'd love to see the green or red bar instead...

Teaching testing habits to other developers?

Developers have many different options out there to create fast and relatively maintainable unit test suites. But this takes a great deal of knowledge involved in decoupling modules of code, isolating the code under test within its test context, and using test doubles (stubs, fakes, mocks). What's more confusing is that within the conc...

Why is code quality not popular?

I like my code being in order, i.e. properly formatted, readable, designed, tested, checked for bugs, etc. In fact I am fanatic about it. (Maybe even more than fanatic...) But in my experience actions helping code quality are hardly implemented. (By code quality I mean the quality of the code you produce day to day. The whole topic of so...

Favorite JavaScript Unit Testing Framework

I've really only implemented my own simple code for creating and running simple unit tests in JavaScript. Basically it automatically executes a list of functions and if a function throws an exception it fails, if not it passes. I'm trying to find a good JavaScript Unit Testing Framework to use with my projects going forward, but there a...

How do I prevent Turbine from writing to my console?

That's the question. I'm trying to write some unit tests against it and want to disable its logging so I can more easily find my test output. I tried turning off everything I could think of with the logger (log4j), and it keeps writing to my console. ...

OCUnit test for protocols/callbacks/delegate in Objective-C

Using OCUnit, is there a way to test delegate protocols? I'm trying this, which doesn't work. -(void) testSomeObjDelegate { SomeObj obj = [[SomeObj alloc] initWithDelegate:self]; [obj executeMethod]; } -(void) someObjDelegateMethod { //test something here } I'm going to try calling the obj method on a different thread and have ...

How to run CPPUnit unit tests

I have written few c++ Unit tests using CPPUnit But I do not understand how to run those. Is there any tool like Nunit-gui? Currently I have written and packed tests in a DLL. When i google i found this http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html But i am not able to understand how does it get tests from a DLL...

How to mock a String using mockito?

I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException. I have tried to achieve that using the following code: String nonEncodedString = mock(String.class); when(nonEncodedString.getBytes(anyString())).thenThrow(new UnsupportedEncodingException("Parsing erro...

How to test enum types?

Hey there, i'm currently trying to build a more or less complete set of unit tests for a small library. Since we want to allow different implementations to exist we want this set of tests to be a) generic, so that we can re-use it to test the different implementations and b) as complete as possible. For the b) part i'd like to know if t...

Correctly Unit Test Service / Repository Interaction

I have a method CreateAccount(...) that I want to unit test. Basically it creates an Account Entity and saves it to the DB, then returns the newly created Account. I am mocking the Repository and expecting an Insert(...) call. But the Insert method expects an Account object. This test passes, but it just does not seem correct, becaus...