junit4

Using JUnit categories vs simply organizing tests in separate classes

喜夏-厌秋 提交于 2019-12-01 04:47:13
问题 I have two logical categories of tests: plain functional unit tests (pass/fail) and benchmark performance tests that are just for metrics/diagnostics. Currently, I have all test methods in a single class, call it MyTests : public class MyTests { @Test public void testUnit1() { ... assertTrue(someBool); } @Test public void testUnit2() { ... assertFalse(someBool); } @Test @Category(PerformanceTest.class) public void bmrkPerfTest1() { ... } @Test @Category(PerformanceTest.class) public void

Test invocation: how to do set up common to all test suites

你。 提交于 2019-12-01 04:42:07
Is there a way to know in a JUnit 4 test Class, if the Class was initiated by a Test-Suite ? I have global things that I want to run before all tests (regarding in-memory DB), so I thought doing it in the test-suit. However, I still want to be able to initiate one test at a time without a Test-Suit, So I need to know if I need to initialize the global things in the @Before part of the test... Does any-one know if it's possible ? Matthew Farwell There are several ways to achieve this. The easiest and simplest is to have a 'test' which is run at the beginning and end of your suite which set up

How to run entire JUnit Test Suite from within code

ぐ巨炮叔叔 提交于 2019-12-01 04:30:25
问题 In eclipse, with JUnit 4, you can right click a project or package and click Run as JUnit Test, and it will run all the JUnit tests within that grouping. Is there a way to do this same thing from within the code? 回答1: You can use packages in junit such as JUnitCore like this: public static void main(String[] args){ List tests = new ArrayList(); tests.add(TestOne.class); tests.add(TestTwo.class); for (Class test : tests){ runTests(test); } } private static void runTests(Class test){ Result

unit-testing a ejb3.0 which has another ejb injected

♀尐吖头ヾ 提交于 2019-12-01 03:56:52
问题 How can I unit test the ProcessorBean? Since I only wan't to test the ProcessorBean and not the Dao, I need to stub or mock the Dao, but I have no idea how I could do that with Junit. I'm using Junit4 and Ejb3.0 @Stateless public class ProcessorBean { @EJB private Dao dao; public void process() { //logic to be tested } } 回答1: There's some support in OpenEJB you might find useful in combination with mocking. As an alternative to the EJB 3.0 Embedded EJBContainer API, you can simply build your

JUnit3 and Junit4 XML Reports with Maven

走远了吗. 提交于 2019-12-01 03:51:34
I am trying to figure out how to use the supposed reporting capabilities of JUnit (3 and 4) in conjunction with Maven, but Google searches aren't turning up much in the way of how to actually run JUnit (via Maven), get a report for each test (or all tests) and what format it will be in. So, my multi-part questions is: 1.) What sort of XML format is JUnit (3/4) capable of outputting? 2.) What sort of calling convention/arguments are required for JUnit to output these reports? 3.) Where are the reports output? 4.) Can these reports be generated while running via Maven or is my only option to use

@parameters method is executed before @beforeclass method

浪子不回头ぞ 提交于 2019-12-01 03:14:24
I'm using "parametrized" feature of junit 4 and I noticed that @parameters method is executed before @beforeclass method. This is creating a problem for me because the parameters i'm passing to the test cases via @parameters depends on the code initialize in the @beforeclass method. For example @RunWith(Parameterized.class) public class TestOtherClass { String argument; private static boolean initializeThis; public TestOtherClass(String parameter) throws Exception { argument=parameter; } @BeforeClass public static void doSetup() { System.out.println("Doing setup before class...");

Test invocation: how to do set up common to all test suites

ぐ巨炮叔叔 提交于 2019-12-01 02:52:53
问题 Is there a way to know in a JUnit 4 test Class, if the Class was initiated by a Test-Suite ? I have global things that I want to run before all tests (regarding in-memory DB), so I thought doing it in the test-suit. However, I still want to be able to initiate one test at a time without a Test-Suit, So I need to know if I need to initialize the global things in the @Before part of the test... Does any-one know if it's possible ? 回答1: There are several ways to achieve this. The easiest and

Run JUnit Test suite from command line

孤者浪人 提交于 2019-12-01 02:41:14
问题 How do I run a Junit 4.8.1 Test suite from command line ? Also I want to use the categories introduces with JUnit 4.8 , is there a way where I can specify from command line the category which I want to run. 回答1: There is no way (as of 4.8) to specify categories from the command line. 回答2: Using java run JUnitCore class (also see here). Categories are supposed to be used with test suites with @RunWith(Categories.class) , @IncludeCategory and @ExcludeCategory . I am not aware of any dynamic way

What do I use instead of Whitebox in Mockito 2.2 to set fields?

六眼飞鱼酱① 提交于 2019-12-01 02:22:28
When using Mockito 1.9.x I have been using Whitebox to set values of fields to "inject" mocks. Se example below: @Before public void setUp() { eventHandler = new ProcessEventHandler(); securityService = new SecurityServiceMock(); registrationService = mock(RegistrationService.class); Whitebox.setInternalState(eventHandler, "registrationService", registrationService); Whitebox.setInternalState(eventHandler, "securityService", securityService); } I really like this approach, but now that I tried to upgrade to Mockito 2.2.7 I noticed (or rather, my IDE noticed and told me quite a few times) that

How to click in a specific part of a Button using Selenium, for the list of options to be displayed?

五迷三道 提交于 2019-12-01 00:48:57
<table id="ext-comp-1389" class="x-btn x-btn-text-icon " cellspacing="0" style="width: auto;"> <tbody class="x-btn-small x-btn-icon-small-left"> <tr> <tr> <td class="x-btn-ml"> <td class="x-btn-mc"> <em class="x-btn-split" unselectable="on"> <button id="ext-gen128" class="x-btn-text create" type="button">New</button> </em> </td> <td class="x-btn-mr"> <i> </i> </td> </tr> <tr> </tbody> </table> Above is how the HTML element is embedded..! The HTML element is a 'New' button with a '+' sign next to it...If, I click on the '+' only, I can get the menu options, which are something like, 'D', 'P',