Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to test all files in a folder

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to test all files in a folder

    Im doing some junit test. I have a bunch of files in a folder and have to test each one. Some of them freeze during the process that why i added the time out. I wanna do a loop to add all the files to the array and the run the test. As I have it now I have to put what indexes of the list i want to test manually. I tried doing a for loop but it tells me that the method is static and i cant add the files that way.
    Thank you in advance...

    /**
     * 
     * Load assumptions and goal from file.
     */
    package testFromFiles;
     
    import java.io.File;
    import java.util.Arrays;
    import java.util.List;
     
    import junit.framework.TestCase;
     
    //import org.junit.After;
    //import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import org.junit.runners.Parameterized.Parameters;
    @RunWith(Parameterized.class)
    public class TPTPTestsAngel extends TestCase {
    	/**
    	 * @param args
    	 * @throws Exception 
    	 */
     
     
    	public TPTPTestsAngel(int number)
    	{
    		this.x = number;
     
    	}
    	String folderName = "//usr//local//Tools//projects//ParsedFiles//PUZ PrIKL//";
    	File folder = new File(folderName);
    	String[] files = (folder.list()) ;
    	TPTPTests nt;
    	static int x ;
     
     
    	@Parameters
    	  public static List<Integer[]>  data() {
     
    	    Integer[][] data = new  Integer[][]{{25},{65},{15}};
    	    return Arrays.asList(data);
    	  }
     
     
     
    	public void testRunTrue(int x) throws Exception
    	{
    			nt = new TPTPTests (folderName,files[x],files.length);
    			nt.setFileName(files[x]);
    			nt.testTPTPTrue();
    	}
     
    	public void testRunFalse(int x) throws Exception
    	{
    			nt = new TPTPTests (folderName,files[x],files.length);
    			nt.setFileName(files[x]);
    			nt.testTPTPAssertFalse();
     
    	}
    	public void testRunUnknown(int x) throws Exception
    	{
    		nt = new TPTPTests (folderName,files[x],files.length);
    		nt.setFileName(files[x]);
    		nt.testTPTPUnknown();
    	}
    	@Test(timeout = 5000)
    	public void LoopTestTrue() throws Exception
    	{
    		testRunTrue(x);
    	}
     
    	@Test(timeout = 5000)
    	public void LoopTestFalse() throws Exception
    	{
    		testRunFalse(x);
    	}
     
    	@Test(timeout = 5000)
    	public void LoopTestUnknown() throws Exception
    	{
    		testRunUnknown(x);
    	}
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to test all files in a folder

    it tells me that the method is static
    Please copy and paste here the full text of the error message.


    What is the "it"
    Last edited by Norm; July 27th, 2011 at 03:26 PM.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: How to test all files in a folder

    It's hard for us to attempt to compile this because it contains non standard imports and you have provided no link to the junit download.

    As Norm says, It's worth posting the entire error message.

    If it is telling you the method cannot be static, try removing the static modifier in the method.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Seraching through files in a folder for a pattern match inside the files.
    By dazzabiggs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 2nd, 2011, 08:35 AM
  2. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM
  3. Listing files in a folder in a .jar
    By kulan8 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: December 22nd, 2010, 08:18 AM
  4. Getting information from a folder
    By shadihrr in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 23rd, 2010, 04:13 PM
  5. Java program to take new files from one path and sent it do another path?
    By jazz2k8 in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: July 8th, 2008, 06:47 AM