Is it possible to run an external command before running tests in a given JUnit file? I run my tests using the Eclipse’s Run command. Using JUnit 4.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Very vague question. Specifically, you didn’t mention how you are running your JUnit tests. Also you mentioned ‘file’, and a file can contain several JUnit tests. Do you want to run the external command before each of those tests, or before any of them are executed?
But more on topic:
If you are using JUnit 4 or greater then you can tag a method with the
@Beforeannotation and the method will be executed before each of your tagged@Testmethods. Alternatively, tagging a static void method with@BeforeClasswill cause it to be run before any of the@Testmethods in the class are run.If you are using a version of JUnit earlier than 4, then you can override the
setUp()andsetUpBeforeClass()methods as replacements for@Beforeand@BeforeClass.