2

This is a simulation of the test suite I want to run with selenium webdriver. Running through everything will generate 128 test-cases which are too ambiguous. I plan to reduce it to 32 by only allowing it to run by making 4 as the divisible factor. So, that it only executes at 4, 8, 12, 14, 16, 20 .... How do I achieve this?

class Class1
    {
        public static String[] test1 = { "1", "2" };
        public static String[] test2 = { "a", "b" };
        public static String[] test3 = { "3", "4" };
        public static String[] test4 = { "c", "d" };
        public static String[] test5 = { "5", "6" };
        public static String[] test6 = { "e", "f" };
        public static String[] test7 = { "7", "8" };

        public static int count = 0;
        public static String[] lines = { };
        static int[] counter;

            public static void Main(String[] args)
            {
                foreach(var i in test1)
                {
                    foreach(var j in test2)
                    {
                        foreach (var k in test3)
                        {
                            foreach (var l in test4)
                            {
                                foreach (var m in test5)
                                {
                                    foreach (var n in test6)
                                    {
                                        foreach (var o in test7)
                                        {
                                            ++count;
                                            counter = new int[count];
                                            var allButFirst3Numbers = counter.SkipWhile(c => c % 3 != 0);
                                            String str = allButFirst3Numbers.ToString();
                                            File.WriteAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt", str.ToString());
                                                String Readfiles = File.ReadAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt");
                                                Int32 myInt = Int32.Parse(Readfiles);
                                                String start = myInt.ToString() + "   " + "(" + i + "  " + j + "  " + k + "  " + l + "  " + m + "  " + n + "  " + o + ")";
                                                Array.Resize(ref lines, lines.Length + 1);
                                                lines[lines.GetUpperBound(0)] = start;
                                                File.WriteAllLines(@"C:\Users\ken4ward\Desktop\Tidy\Writing.txt", lines);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
    }
6
  • What do you mean by "too ambiguous"?
    – user246
    Jun 18 '15 at 15:18
  • 2
    if (count % 4) == 0 then run the test else don't run the test.
    – user246
    Jun 18 '15 at 15:19
  • It didn't work.
    – ken4ward
    Jun 18 '15 at 16:31
  • 5
    Wow that is a lot of foreach loops. I would recommend against doing something like that because it is extremely difficult to track.
    – Paul Muir
    Jun 19 '15 at 16:46
  • 2
    What are you trying to accomplish there ? Im sure there is a better way than 7 foreach loops to write some characters in text file.
    – George
    Feb 7 '17 at 14:40
0

Below are few snippets to SKIP test

  • Solution 1

Add snippet in pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
  <configuration>
      <skipTests>true</skipTests>
  </configuration> 
</plugin>

skip the tests via the command line by executing the following command:

mvn install -DskipTests

OR

mvn install -Dmaven.test.skip=true

  • Solution 2

In TestNG,

@Test(enabled=false)

annotation is used to skip a test case. Check below example to

  1. skip test
  2. throw skip exception
  3. conditional skip

    public class SkipExample {
    
    @Test(enabled=false)
    public void testCaseEnabling(){
            System.out.println("I'm Not Ready, please don't execute me");
        }
    @Test
    public void testCaseSkipException(){
            System.out.println("Im in skip exception");
            throw new SkipException("Skipping this exception");
        }
    
    @Test
    public void testCaseConditionalSkipException(){
        System.out.println("Im in Conditional Skip");
        if(!DataAvailable)
        throw new SkipException("Skipping this exception");
        System.out.println("Executed Successfully");
    }
    
    }
    

Not the answer you're looking for? Browse other questions tagged or ask your own question.