user3605138
user3605138

Reputation: 37

Is a test using multiple methods of the same class a unit test?

If I create a unit test using multiple methods of the class under test, is it still a unit test? For example,

@TestFixture
public class TestBehavior {
    @Test
    public void testA() {
        // arrange
        Model sut = new Model();

        // act
        string actual = sut.doA(5, sut.doB());

        // assert
        assertEqual(expected, actual);
    }
}

Can it be considered a unit test? Or some bastardized integration test, because its calling doB()? And what if it was a different object of the same class that is calling doB()?

Upvotes: 0

Views: 520

Answers (1)

conFusl
conFusl

Reputation: 939

The definition of unit depends strongly on your use case - in some cases it's only one method, in other cases a couple of methods or a whole class.

In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure. In object-oriented programming, a unit is often an entire interface, such as a class, but could be an individual method.

Look at this link for an interesting paper about unit tests in object oriented programming ("Towards a Framework for Differential Unit Testing of Object-Oriented Programs")!

Upvotes: 1

Related Questions