unit-testing

Self Testing Systems.

I had an idea I was mulling over with some colleagues. None of us knew whether or not it exists currently. The Basic Premise is to have a system that has 100% uptime but can become more efficient dynamically. Here is the scenario: * So we hash out a system quickly to a specified set of interfaces, it has zero optimizations, yet...

Mocking Static Blocks in Java

My motto for Java is "just because Java has static blocks, it doesn't mean that you should be using them." Jokes aside, there are a lot of tricks in Java that make testing a nightmare. Two of the most I hate are Anonymous Classes and Static Blocks. We have a lot of legacy code that make use of Static Blocks and these are one of the annoy...

Where do the Python unit tests go?

If you're writing a library, or an app, where do the unit test files go? It's nice to separate the test files from the main app code, but it's awkward to put them into a "tests" subdirectory inside of the app root directory, because it makes it harder to import the modules that you'll be testing. Is there a best practice here? ...

What Makes a Good Unit Test?

I'm sure most of you are writing lots of automated tests and that you also have run into some common pitfalls when unit testing. My question is do you follow any rules of conduct for writing tests in order to avoid problems in the future? To be more specific: What are the properties of good unit tests or how do you write your tests? L...

Unit Testing Monorail's RedirectToReferrer()

Hello, I am trying to write a unit test for an action method which calls the Controller.RedirectToReferrer() method, but am getting a "No referrer available" message. How can I isolate and mock this method? Thanks, -- rauchy ...

How do you know what to test when writing unit tests?

Using C#, I need a class called User that has a username, password, active flag, first name, last name, full name, etc. There should be methods to Authenticate and Save. Do I just write a test for the methods and do I even need to worry about testing the properties since they are .net getter & setters? ...

Rhino Mocks, TypeMock, Moq, or NMock? Which one do you use and why?

Which one do you use (if you use the listed ones) and what do you love and even hate about it? ...

Disadvantages of Test Driven Development?

What do I lose by adopting test driven design? List only negatives; do not list benefits written in a negative form. ...

Private Accessor class ignores generic constraint

These days, i came across a problem with Team System Unit Testing. I found that the automatically created accessor class ignores generic constraints - at least in the following case: Assume you have the following class: namespace MyLibrary { public class MyClass { public Nullable<T> MyMethod<T>(string s) where T : struct { ret...

C++ Unit Testing Legacy Code: How to handle #include?

I've just started writing unit tests for a legacy code module with large physical dependencies using the #include directive. I've been dealing with them a few ways that felt overly tedious (providing empty headers to break long #include dependency lists, and using #define to prevent classes from being compiled) and was looking for some b...

Directory layout for PHPUnit tests?

I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working. When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this - /src MyClass.java /test MyClassTest.java and so on. When unit testing with PHPUnit, is it common to foll...

Unit Testing C Code

I worked on an embedded system this summer written in straight C. It was an existing project that the company I work for had taken over. I have become quite accustomed to writing unit tests in Java using JUnit but was at a loss as to the best way to write unit tests for existing code (which needed refactoring) as well as new code added...

Is Unit Testing worth the effort?

I am working to integrate unit testing into the development process on the team I work on and there are some skeptics. What are some good ways to convince the skeptical developers on the team of the value of Unit Testing? In my specific case we would be adding Unit Tests as we add functionality or fixed bugs. Unfortunately our code base ...

Execute JavaScript from within a C# assembly

I'd like to execute JavaScript code from within a C# assembly and have the results of the JavaScript code returned to the calling C# code. It's easier to define things that I'm not trying to do: I'm not trying to call a JavaScript function on a web page from my code behind. I'm not trying to load a WebBrowser control. I don't want to ...

Good ways to test a unit that communicates via HTTP

Often, I find myself wanting to write a unit test for a portion of code that accesses HTTP resources as part of its normal function. Have you found any good ways to write these kinds of tests? ...

How do you unit-test code that interacts with and instantiates third-party COM objects?

One of the biggest issues currently holding me back from diving full steam into unit testing is that a really large percentage of the code I write is heavily dependent on third-party COM objects from different sources that also tend to interact with each other (I'm writing add-ins for Microsoft Office using several helper libraries if yo...

How to run TAP::Harness tests written in Guile?

The usual approach of test: $(PERL) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INCDIRS)')" $(TEST_FILES) fails to run Guile scripts, because it passes to Guile the extra parameter "-w". ...

How to build unit tests in Guile, which output to the TAP standard?

I would like to have a Guile script, which implements functions, which output test result messages according to the TAP protocol. ...

Python's unittest logic

Can someone explain this result to me. The first test succeeds but the second fails, although the variable tested is changed in the first test. >>> class MyTest(unittest.TestCase): def setUp(self): self.i = 1 def testA(self): self.i = 3 self.assertEqual(self.i, 3) def testB(self): self.assertEqual(self.i,...

How does one unit test sections of code that are procedural or event-based

I'm convinced from this presentation and other commentary here on the site that I need to learn to Unit Test. I also realize that there have been many questions about what unit testing is here. Each time I go to consider how it should be done in the application I am currently working on, I walk away confused. It is a xulrunner applica...