Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD: Is it plausible to have integration tests, but no unit tests?

Technology Stack: .NET 4, C#, NUnit

I am attempting to apply test driven development to a new project that performs image processing. I have a base class that contains shared file I/O methods and subclasses that perform various specific processing algorithms. As I understand it, unit tests do not touch the file system or other objects, and mock behavior where that occurs. My base class only contains simple accessors and straightforward file system I/O calls.

public class BaseFile
{
    public String Path { get; set; }

    public BaseFile()
    {
        Path = String.Empty;
    }

    public BaseFile(String path)
    {
        if (!File.Exists(path))
        {
            throw new FileNotFoundException("File not found.", path);
        }

        Path = path;
    }
}

Is there any value in testing these methods? If so, how could I abstract away the calls to the file system?

My other question is how to test the subclass which is specific to a type of image file (~200 MB). I have searched the site and found similar questions, but none dealing with the file sizes I am working with on this project. Is it plausible for a class to have integration tests (using a "golden file"), but no unit tests? How could I strictly follow TDD methods and first write a failing test in this case?

like image 924
Noren Avatar asked Feb 15 '12 16:02

Noren


People also ask

Can we do integration testing without unit testing?

Unit testing and integration testing are both important parts of successful software development. Although they serve different yet related purposes, one cannot replace the other.

Is TDD for unit testing or integration testing?

Unit testing is a component of TDD, a pragmatic methodology that applies a careful approach to product creation through continuous testing and auditing. This testing method is also the first level of software testing that is performed before other testing methods, such as integration testing.

Does TDD include integration test?

And the answer to your question is Yes - TDD includes integration tests. That's the only way not to break the golden rule of TDD.

Why is integration testing needed even if we have good unit testing in place?

Integration testing These tests are necessary to make sure components work correctly together – your unit tests may show that each part works correctly, but there may be data or logic errors that only show up when the components are tested outside of isolation.


1 Answers

In answer to your first question, yes there is value in testing these methods. I have published a library that facilitates doing exactly that without actually hitting the file system: https://bitbucket.org/mylesmcdonnell/mpm.io/wiki/Home

In (not an) answer to your second question I would need to see some code, but I suspect you may need to take a similar approach to the above lib. namely; define interface, define proxy to concrete, define factory to return proxy or mock.

like image 73
Myles McDonnell Avatar answered Nov 08 '22 19:11

Myles McDonnell