Call a software JUnit test

I would like to run the JUnit programmatic method. I know that I can run the entire test using the following code snippet:

Class<?> test = Class.forName("MyTestClass"); JUnitCore junit = new JUnitCore(); Result result = junit.run(test); 

However, I would like to run a specific method in this test class that contains several methods.

It would also be great if I could control the behavior of setUp / tearDown.

thanks

+4
source share
1 answer

There is overloaded the version of JUnitCore # run , which accepts Request . Although Request has a # factory request method for:

Create a query that will perform one test during processing. This is done by filtering all other tests. This method is used to support repeated single tests.

If you need to control #setUp / #tearDown (i.e., methods marked with @Before and / or @After ), you can extend the class and override methods you need to change.

+4
source

Source: https://habr.com/ru/post/1490507/


All Articles