TDD and private methods/classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Woods

    TDD and private methods/classes

    Hi

    I'm still trying to get my head around how to do TDD.

    I have a situation where I have a set of classes which build a tree
    which contains nested (subselect) SQL statements. The tree is completely
    internal to my project and there is no need to make it public in any
    way. The logic is pretty complex (for me anyway) and so I want to be
    able to test it with a variety of test cases. The tree generates SQL
    which is then used to create a dataset and this is the public object.

    However, I understand that TDD only tests the public interfaces ... but
    that's not good enough as the dataset will be other things are well
    (e.g. formatting values etc)

    So my question is, what is the TDD way for testing my SQL generation. At
    the moment I have included a public Test Class which instantiates and
    builds my SQL tree thus allow me to see how it is behaving, but I'm not
    sure that this is the right/best way.

    Could someone explain alternative strategies which are perhaps "more TDD".

    Thanks

    Simon
  • Bill McCarthy

    #2
    Re: TDD and private methods/classes

    You can use TDD on private methods. Just be aware it involves using
    reflection , and hence strings in places, so if you refactor your code, it's
    hard to keep the tests in sync.


    "Simon Woods" <simonjwoods@ho tmail.comwrote in message
    news:u7HStEcqIH A.1952@TK2MSFTN GP05.phx.gbl...
    Hi
    >
    I'm still trying to get my head around how to do TDD.
    >
    I have a situation where I have a set of classes which build a tree which
    contains nested (subselect) SQL statements. The tree is completely
    internal to my project and there is no need to make it public in any way.
    The logic is pretty complex (for me anyway) and so I want to be able to
    test it with a variety of test cases. The tree generates SQL which is then
    used to create a dataset and this is the public object.
    >
    However, I understand that TDD only tests the public interfaces ... but
    that's not good enough as the dataset will be other things are well (e.g.
    formatting values etc)
    >
    So my question is, what is the TDD way for testing my SQL generation. At
    the moment I have included a public Test Class which instantiates and
    builds my SQL tree thus allow me to see how it is behaving, but I'm not
    sure that this is the right/best way.
    >
    Could someone explain alternative strategies which are perhaps "more TDD".
    >
    Thanks
    >
    Simon

    Comment

    • Simon Woods

      #3
      Re: TDD and private methods/classes

      Thanks Bill

      So is there a better way of architecturing/thinking abnout it?

      S

      Bill McCarthy wrote:
      You can use TDD on private methods. Just be aware it involves using
      reflection , and hence strings in places, so if you refactor your code,
      it's hard to keep the tests in sync.
      >
      >
      "Simon Woods" <simonjwoods@ho tmail.comwrote in message
      news:u7HStEcqIH A.1952@TK2MSFTN GP05.phx.gbl...
      >Hi
      >>
      >I'm still trying to get my head around how to do TDD.
      >>
      >I have a situation where I have a set of classes which build a tree
      >which contains nested (subselect) SQL statements. The tree is
      >completely internal to my project and there is no need to make it
      >public in any way. The logic is pretty complex (for me anyway) and so
      >I want to be able to test it with a variety of test cases. The tree
      >generates SQL which is then used to create a dataset and this is the
      >public object.
      >>
      >However, I understand that TDD only tests the public interfaces ...
      >but that's not good enough as the dataset will be other things are
      >well (e.g. formatting values etc)
      >>
      >So my question is, what is the TDD way for testing my SQL generation.
      >At the moment I have included a public Test Class which instantiates
      >and builds my SQL tree thus allow me to see how it is behaving, but
      >I'm not sure that this is the right/best way.
      >>
      >Could someone explain alternative strategies which are perhaps "more
      >TDD".
      >>
      >Thanks
      >>
      >Simon
      >

      Comment

      Working...