#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    21
    Rep Power
    0

    Test Java code??


    Hey guy, I would like to know how I can test my function in this programm? What kind of opportunities I have? Have someone examples for me? Thanks...

    a Code:
    import java.io.*;
    import java.util.Arrays;
     
    public class palindromeString
        {
            public static void main(String args[])throws IOException
            {
            	/*Read into Buffer*/
            	int x = 1;
            	while(x>0){//continuous loop
                BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Enter a first Parameter");
                String prm1 = bfr.readLine();
                System.out.println("Enter a second Parameter");
                String prm2 = bfr.readLine();
                char[] prm1chars = prm1.toCharArray();
                char[] prm2chars = prm2.toCharArray();
                Arrays.sort( prm1chars );
                Arrays.sort( prm2chars );
                /*compare both string*/
                boolean isAnangram = new String(prm1chars).equalsIgnoreCase(new String(prm2chars));
                System.out.println( isAnangram );  
            	}//End while
        }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    I don't understand your question. Are you able to compile it? Can you run it?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    21
    Rep Power
    0
    Like this!

    http://en.wikipedia.org/wiki/Software_testing


    I wanna test my programm. What is the best way...Junit, ....?

    Have someone an example or so or a good link?
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    Does it compile without errors?
    If there are no errors, do you know how to use the java command to execute it?

    See the tutorial: http://docs.oracle.com/javase/tutori...ava/index.html
    Follow the link for your OS.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    21
    Rep Power
    0
    Its without error...! What I mean is, when you programm a software then you want to test it. I know there are a lot of kind of testing. For example unit testing....! I think I will read something about unit testing...!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    38
    Rep Power
    9
    For something as simples as that the tests you make is if it works as it should not a huge amount of complicated tests for that
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18
    Originally Posted by machupicchu
    Its without error...! What I mean is, when you programm a software then you want to test it. I know there are a lot of kind of testing. For example unit testing....! I think I will read something about unit testing...!
    There are indeed a lot of kinds of testing. Unit testing being one of them at the code level. Others include unit integration testing, funtional testing and user acceptance. I understand your question: your code compiles, your program runs and you get some output, yet : is the output correct? Does each function and class does what it is meant to do?
    This means that you can test functions and classes separately.

    An example of a test can be:
    Code:
    public void testReverse() {
        string expectedAnswer = "cba";
        string answer = myReverseFunction("abc");
        assertEquals(answer, expectedAnswer);
    }
    I can advise you to look at TDD (Test Driven Development). This paradigm says that you design tests first before you start coding. You keep running your testsuite until all tests are passed, if not: keep changing the code.
    Also: look at the terms "stub" and "driver"

IMN logo majestic logo threadwatch logo seochat tools logo