Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We are currently developing a public API for our app. The methods on this public API are mostly putting together functionality in different corners of the system. An example would be: (names have been changed to protect the innocent)

public String createAppUser(String app, String name, String email, byte[] pwd) { 
     Application appl = applicationModule.retrieve(app);
     User user = userModule.createUser(name,email);
     Digest digest = cryptoModule.createDigest(pwd);
     authenticationModule.authorize(user,appl,digest);
     accountingModule.createAccount(user,appl);
     return user.getId();
}

When unit testing such a thing, the unit test is just a copy of the same workflow, with some additional noise to setup mocks, objects and validate interactions. Although I find unit-test of algorithmic parts of the application essential, in this 'workflow' part, I find unit-test a repetition of the workflow in question form. Following the DRY principle, it feels like a waste of time. What are the best practices in these cases?

Given that these methods are part of a public API, I would find more valuable to test them through a client and validate that the system effects have taken place. This is more 'system test' or 'integration test' and beyond the scope of unit test.

What would be the best test approach in this context?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You're right: this falls under the 'integration test' category. And with integration tests, I tend to not mock anything other than very external resources (like a web page or network file), since you're supposed to be testing how the real components interact with one another.

In those cases, just assert that the proper application states have been changed and that the output looks fine. In this case running the method and simply confirming that the users table has been modified, that they're authorized, and that you get an ID back.

share|improve this answer
    
Just for the record: I went through the unit tests, mostly checking for pre & post conditions and specially exceptions. I found plenty of issues that needed to be corrected, so although my first impression was 'lost time', my conclusion after the facts is that both types of tests are valuable. Unit tests to ensure that the unit of code is doing as expected and the integration test to ensure that the system response is correct. –  maasg Oct 17 '11 at 17:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.