Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    I'll just paste this from another forum.

    I don't know if it's me but I'm reading a book which has absolutely failed to explain how test code is used and why it useful.

    Usually I would just write code and then click run to see if it's correct. But now the book says that when writing a program I should use test code.

    It is really bad at showing what it is actually doing, even though the program is only using two classes. It is a game of battleships.

    One class, call it Battleship, has two methods, String checkUsersGuess(String usersGuess) and void setCellLocations() (Sets ship location).

    I can't even tell what it's done. It just seems like it's written normal code and called it test code, as if it's not real code. I'm very confused and hope someone can please explain this concept to a beginner.

    The other class, call it BattleShipGame, has the main method.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by eagleclawsan)
    I'll just paste this from another forum.

    I don't know if it's me but I'm reading a book which has absolutely failed to explain how test code is used and why it useful.

    Usually I would just write code and then click run to see if it's correct. But now the book says that when writing a program I should use test code.

    It is really bad at showing what it is actually doing, even though the program is only using two classes. It is a game of battleships.

    One class, call it Battleship, has two methods, String checkUsersGuess(String usersGuess) and void setCellLocations() (Sets ship location).

    I can't even tell what it's done. It just seems like it's written normal code and called it test code, as if it's not real code. I'm very confused and hope someone can please explain this concept to a beginner.

    The other class, call it BattleShipGame, has the main method.
    I've never bothered with test code - too much like hard work. If your method works then keep using it, there's no point fixing something that isn't broken.

    Posted from TSR Mobile
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Andy98)
    I've never bothered with test code - too much like hard work. If your method works then keep using it, there's no point fixing something that isn't broken.

    Posted from TSR Mobile
    But I'd still like to understand how's it's used if possible. Most sources seem to require you to know everything else when explaining test code.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by eagleclawsan)
    But I'd still like to understand how's it's used if possible. Most sources seem to require you to know everything else when explaining test code.
    I've honestly got no clue for test code, as I said I never bothered with it.

    Posted from TSR Mobile
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Andy98)
    I've honestly got no clue for test code, as I said I never bothered with it.

    Posted from TSR Mobile
    So can I assume it's not important? Do you study Computer Science? I love the idea about of going straight into the real code rather than messing around with test code as well.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by eagleclawsan)
    So can I assume it's not important? Do you study Computer Science? I love the idea about of going straight into the real code rather than messing around with test code as well.
    Not yet, they wouldn't let me at school so I'm doing it at college from September. But my dad's a computer programmer so I picked up bits of code from him, then taught myself the rest.

    Posted from TSR Mobile
    Offline

    3
    ReputationRep:
    (Original post by Andy98)
    I've honestly got no clue for test code, as I said I never bothered with it.
    Hahaha...
    Testing is vital when you join the real world.




    Your book is probably talking about Unit Tests (UTs). They invoke a unit of code and then then checks the output to ensure it is correct.

    So if you setup a test to have a ship in A1, you should then be able to test that if you use the method to guess A1 it should return a hit - if it doesn't there is something wrong.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by Push_More_Button)
    Hahaha...
    Testing is vital when you join the real world.




    Your book is probably talking about Unit Tests (UTs). They invoke a unit of code and then then checks the output to ensure it is correct.

    So if you setup a test to have a ship in A1, you should then be able to test that if you use the method to guess A1 it should return a hit - if it doesn't there is something wrong.
    No I mean I test by using it, not through test code.

    Posted from TSR Mobile
    Offline

    3
    ReputationRep:
    (Original post by Andy98)
    No I mean I test by using it, not through test code.
    Then it's inadequate testing, as you're certainly going to miss things unless your software is incredibly simple.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by Push_More_Button)
    Then it's inadequate testing, as you're certainly going to miss things unless your software is incredibly simple.
    It works so why change?

    Posted from TSR Mobile
    Offline

    3
    ReputationRep:
    How do you know it works if you're fully testing?

    It's an incredibly bad habit to have and when you go to programming in the real world you'll have a real shock. It's better to break that habit now and do it properly.
    • Study Helper
    • Welcome Squad
    Offline

    18
    ReputationRep:
    Study Helper
    Welcome Squad
    (Original post by Push_More_Button)
    How do you know it works if you're fully testing?

    It's an incredibly bad habit to have and when you go to programming in the real world you'll have a real shock. It's better to break that habit now and do it properly.
    I'm waiting to go to college and uni to learn that sort of stuff, but it works for what I do at the moment - for websites there is not that much to test, if it looks OK it's OK

    Posted from TSR Mobile
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Would you like to hibernate through the winter months?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.