0

I am having a excel sheet having testcases name and some values related to it eg: TestCase2 Value2, TestCase1 Value1.

I have a Junit class having test methods(TestCase1(), TestCase2()) as the same name I have in excel sheet So when I run my Junit class I want the test methods to execute serially the way they are mentioned in excel file as in this case testcase2 should execute before testcase1.

Prasad Madge
  • 71
  • 1
  • 14
  • So you want to build a TestSuite of tests using names based on some input.... – Peter Lawrey Jan 21 '16 at 10:00
  • Why are you using an excel sheet for this? You want the tests to be usable by some user? If that is the case you could think of FitNesse. – Chris311 Jan 21 '16 at 10:05
  • Yes Peter , Test case method names will be coming from excel sheet and they should execute serially the way they are mentioned – Prasad Madge Jan 21 '16 at 10:20

1 Answers1

0

Method 1: Use Excel to construct and launch command lines, with Excel/windows capabilities (VBscript, ...).

To launch junit tests:

java org.junit.runner.JUnitCore [test class name]

see that: How to run JUnit test cases from the command line

Note that you can launch a class, not a particular method.

For particular method, see that: Run single test from a JUnit class using command-line

For the order of methods, see below.

But, how you get and exploit results is another thing.

Method 2 (prefered): Control everything from Java:

Read excel file, with proper library:

How to read and write excel file in java

or, change it to csv, or OpenOffice (odf), and read with other libraries.

Iterate, and launch each method by its name by reflexivity:

getMethod and Invoke.

See that: How do I invoke a Java method when given the method name as a string?

Order of tests:

Set this before the class:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

Then your tests will be executed in lexical order

Hope it helps !

Community
  • 1
  • 1