Search Results

Search found 539 results on 22 pages for 'junit'.

Page 12/22 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • GWT and Mock the view in MVP pattern

    - by Yannick Eurin
    Hello, i dunno if the question is already ask, but i couldn't find it... i'm searching a way to mock my view in order to test my presenter ? i try to use mockito for the view, and set it in the presenter, but in result in presenter, when i call presenter.getDisplay() (the getter for the view) all of my widget is null ? as i believe it's normal mockito will not mock the widget. i'm 100% sure i mistaken something but i couldnt find it. thanks for your enlightement :)

    Read the article

  • How to make @BeforeClass run prior Spring TestContext loads up ?

    - by lisak
    Hey, it should be piece of cake for programmers using testNG. I have this scenario @ContextConfiguration(locations={"customer-form-portlet.xml", "classpath:META-INF2/base-spring.xml" }) public class BaseTestCase extends AbstractTestNGSpringContextTests { ... @BeforeClass public void setUpClass() throws Exception { But I'd need the spring context to be load up after @BeforeClass. I I came up with overriding AbstractTestNGSpringContextTests methods : @BeforeClass(alwaysRun = true) protected void springTestContextBeforeTestClass() throws Exception { this.testContextManager.beforeTestClass(); } @BeforeClass(alwaysRun = true, dependsOnMethods = "springTestContextBeforeTestClass") protected void springTestContextPrepareTestInstance() throws Exception { this.testContextManager.prepareTestInstance(this); } and make my method @BeforeClass(alwaysRun = true, dependsOnMethods = "setUpClass") protected void springTestContextPrepareTestClass() throws Exception { } But then I get : Caused by: org.testng.TestNGException: org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance() is not allowed to depend on protected void org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextBeforeTestClass() throws java.lang.Exception Make it public also doesn't help. Could please anybody mention here if it can be done in a working manner :-) I know that I could load the testContext manually, but that wouldn't be so fancy. It works like this, but TestContextManager is not visible so I can't call prepareTestInstance() method on it : @Override @BeforeClass(alwaysRun = true, dependsOnMethods = "setUpClass") public void springTestContextPrepareTestInstance() throws Exception { }

    Read the article

  • mockito mock a constructor with parameter

    - by Shengjie
    I have a class as below: public class A { public A(String test) { bla bla bla } public String check() { bla bla bla } } The logic in the constructor A(String test) and check() are the things I am trying to mock. I want any calls like: new A($$$any string$$$).check() returns a dummy string "test". I tried: A a = mock(A.class); when(a.check()).thenReturn("test"); String test = a.check(); // to this point, everything works. test shows as "tests" whenNew(A.class).withArguments(Matchers.anyString()).thenReturn(rk); // also tried: //whenNew(A.class).withParameterTypes(String.class).withArguments(Matchers.anyString()).thenReturn(rk); new A("random string").check(); // this doesn't work But it doesn't seem to be working. new A($$$any string$$$).check() is still going through the constructor logic instead of fetch the mocked object of A.

    Read the article

  • Need help with writing test

    - by London
    I'm trying to write a test for this class its called Receiver : public void get(People person) { if(null != person) { LOG.info("Person with ID " + person.getId() + " received"); processor.process(person); }else{ LOG.info("Person not received abort!"); } } Here is the test : @Test public void testReceivePerson(){ context.checking(new Expectations() {{ receiver.get(person); atLeast(1).of(person).getId(); will(returnValue(String.class)); }}); } Note: receiver is the instance of Receiver class(real not mock), processor is the instance of Processor class(real not mock) which processes the person(mock object of People class). GetId is a String not int method that is not mistake. Test fails : unexpected invocation of person.getId() I'm using jMock any help would be appreciated. As I understood when I call this get method to execute it properly I need to mock person.getId() , and I've been sniping around in circles for a while now any help would be appreciated.

    Read the article

  • Unit testing installation of services

    - by skiphoppy
    Our installer program is going to be installing a number of system services, under both Windows and UNIX, using JavaServiceWrapper. There will be a class responsible for creating JavaServiceWrapper config files, installing the services, etc. Can I have some suggestions on how to unit-test this class?

    Read the article

  • Reflection in unit tests for checking code coverage

    - by Gary
    Here's the scenario. I have VO (Value Objects) or DTO objects that are just containers for data. When I take those and split them apart for saving into a DB that (for lots of reasons) doesn't map to the VO's elegantly, I want to test to see if each field is successfully being created in the database and successfully read back in to rebuild the VO. Is there a way I can test that my tests cover every field in the VO? I had an idea about using reflection to iterate through the fields of the VO's as part of the solution, but maybe you guys have solved the problem before? I want this test to fail when I add fields in the VO, and don't remember to add checks for it in my tests.

    Read the article

  • JPA DAO integration test not throwing exception when duplicate object saved?

    - by HDave
    I am in the process of unit testing a DAO built with Spring/JPA and Hibernate as the provider. Prior to running the test, DBUnit inserted a User record with username "poweruser" -- username is the primary key in the users table. Here is the integration test method: @Test @ExpectedException(EntityExistsException.class) public void save_UserTestDataSaveUserWithPreExistingId_EntityExistsException() { User newUser = new UserImpl("poweruser"); newUser.setEmail("[email protected]"); newUser.setFirstName("New"); newUser.setLastName("User"); newUser.setPassword("secret"); dao.persist(newUser); } I have verified that the record is in the database at the start of this method. Not sure if this is relevant, but if I do a dao.flush() at the end of this method I get the following exception: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

    Read the article

  • How do Java mocking frameworks work?

    - by Amir Rachum
    This is NOT a question about which is the best framework, etc. I have never used a mocking framework and I'm a bit puzzled by the idea. How does it know how to create the mock object? Is it done in runtime or generates a file? How do you know its behavior? And most importantly - what is the work flow of using such a framework (what is the step-by-step for creating a test). Can anyone explain? You can choose whichever framework you like for example, just say what it is.

    Read the article

  • Best way to unit test Collection?

    - by limc
    I'm just wondering how folks unit test and assert that the "expected" collection is the same/similar as the "actual" collection (order is not important). To perform this assertion, I wrote my simple assert API:- public void assertCollection(Collection<?> expectedCollection, Collection<?> actualCollection) { assertNotNull(expectedCollection); assertNotNull(actualCollection); assertEquals(expectedCollection.size(), actualCollection.size()); assertTrue(expectedCollection.containsAll(actualCollection)); assertTrue(actualCollection.containsAll(expectedCollection)); } Well, it works. It's pretty simple if I'm asserting just bunch of Integers or Strings. It can also be pretty painful if I'm trying to assert a collection of Hibernate domains, say for example. The collection.containsAll(..) relies on the equals(..) to perform the check, but I always override the equals(..) in my Hibernate domains to check only the business keys (which is the best practice stated in the Hibernate website) and not all the fields of that domain. Sure, it makes sense to check just against the business keys, but there are times I really want to make sure all the fields are correct, not just the business keys (for example, new data entry record). So, in this case, I can't mess around with the domain.equals(..) and it almost seems like I need to implement some comparators for just unit testing purposes instead of relying on collection.containsAll(..). Are there some testing libraries I could leverage here? How do you test your collection? Thanks.

    Read the article

  • Changing the default TestRunner in Eclipse.

    - by Vitalij
    All tests should be run with jUnit3, if i run a non-configured Test, it tries to use the default-TestRunner (jUnit4). So, i have to go into the run/debug configuration, change the TestRunner to "jUnit3" and run it again. On EVERY Test. This just disturbs the workflow. So, is there an option to REMOVE jUnit4 as possible TestRunner, or even better, change the Default TestRunner to jUnit3 ? Thanks in Advance,

    Read the article

  • NetBeans Platform Unit Test Library Dependencies

    - by Ben Hammond
    I am working on a Netbeans Platform RCP application. I use jmock in my unit tests and I have created a Library Wrapper Module to import the necessary libraries. The Module has an section named 'Libraries' and another section named 'Unit Test Libraries'. I hoped that I could add the JMock Library Wrapper to the 'Unit Test Libraries', however when I run the unit tests I get the error 'package org.jmock does not exist'. If I import the JMock Library Wrapper in to the main 'Libraries' element then it works, but this feels wrong. Maven allows me to specify unit-test only dependencies, and I assumed that NetBeans Platform did the same. Should this be possible? Am I doing something wrong? Should I resign myself to a run-time dependency on the unit-test libraries (ugh).

    Read the article

  • How do I test expectedExceptionsMessageRegExp (exception message) using TestNG?

    - by Thomman
    I'm using expectedExceptionsMessageRegExp annotation to test exception message, but the this is not executing correctly.please see the below code. Unit Test code: @Test (dependsOnMethods = "test1", expectedExceptions = IllegalArgumentException.class , expectedExceptionsMessageRegExp = "incorrect argument") public void testConverter() { try { currencyConverter = Converter.convert(val1,val2) } catch (MYException e) { e.printStackTrace(); } } Application code: if (val1 == null || val1.length() == 0) { throw new IllegalArgumentException("Val1 is incorrect"); } The unit test code should check the exception message , if both message are not matching , it should throw fail (unit test failed) . At present this is not happening , Am i doing something wrong?

    Read the article

  • Unit test helper methods?

    - by Aly
    Hi, I have classes which prviously had massive methods so i subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods, is it good to unit test the helper methods too as if one of them fail the public method that calls it will also fail - but this way we can identify why it failed. Also in order to test these using a mock object I would need to change their visibility from private to protected, is this desirable?

    Read the article

  • Where to put common setUp-code for differen testclasses?

    - by Benedikt
    I have several different test classes that require that certain objects are created before those tests can be run. Now I'm wondering if I should put the object initialization code into a separate helper class or superclass. Doing so would surely reduce the amount of duplicate code in my test classes but it would also make them less readable. Is there a guideline or pattern how to deal with common setUp-code for unit tests?

    Read the article

  • Force IOException during file reading

    - by DixonD
    I have the piece of code that reads data from file. I want to force IOException in this code for testing purpose (I want to check if code throws correct custom exception in this case). Is there a some way to create a file which is protected from being read, for example? Maybe dealing with some security checks can help? Please, note that passing name to not-existent file cannot help, because FileNotFoundException has separate catch clause. Here peace of code for better undestanding of question: BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(csvFile)); String rawLine; while ((rawLine = reader.readLine()) != null) { // some work is done here } } catch (FileNotFoundException e) { throw new SomeCustomException(); } catch (IOException e) { throw new SomeCustomException(); } finally { // close the input stream if (reader != null) { try { reader.close(); } catch (IOException e) { // ignore } } }

    Read the article

  • Embedded MongoDB when running integration tests

    - by seanhodges
    My question is a variation of this one. Since my Java Web-app project requires a lot of read filters/queries and interfaces with tools like GridFS, I'm struggling to think of a sensible way to simulate MongoDB in the way the above solution suggests. Therefore, I'm considering running an embedded instance of MongoDB alongside my integration tests. I'd like it to start up automatically (either for each test or the whole suite), flush the database for every test, and shut down at the end. These tests might be run on development machines as well as the CI server, so my solution will also need to be portable. Can anyone with more knowledge on MongoDB help me get idea of the feasibility of this approach, and/or perhaps suggest any reading material that might help me get started? I'm also open to other suggestions people might have on how I could approach this problem...

    Read the article

  • Force orientation change in testcase with fragments

    - by user1202032
    I have an Android test project in which I wish to programatically change the orientation. My test: public class MainActivityLandscapeTest extends ActivityInstrumentationTestCase2<MainActivity> { public MainActivityLandscapeTest() { super(MainActivity.class); } private MainActivity mActivity; private Fragment mDetailFragment; private Fragment mListFragment; private Solo mSolo; @Override protected void setUp() throws Exception { super.setUp(); mSolo = new Solo(getInstrumentation(), getActivity()); mSolo.setActivityOrientation(Solo.LANDSCAPE); mActivity = getActivity(); mListFragment = (Fragment) mActivity.getSupportFragmentManager() .findFragmentById(R.id.listFragment); mDetailFragment = (Fragment) mActivity.getSupportFragmentManager() .findFragmentById(R.id.detailFragment); } public void testPreConditions() { assertTrue(mActivity != null); assertTrue(mSolo != null); assertTrue(mListFragment != null); assertTrue(getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE); } /** * Only show detailFragment in landscape mode */ public void testOrientation() { assertTrue(mListFragment.isVisible()); assertTrue(mDetailFragment.isVisible()); } } The layouts for the activity is in seperate folders, layout-port and layout-land layout-port fragment_main.xml layout-land fragment_main.xml In landscape mode, the layout contains 2 fragments (Detail and list) while in portrait it contains 1(List only). If the device/emulator is already in landscape mode before testing begins, this test passes. If in portrait, it fails with a NullPointerException on mListFragment and mDetailFragment. Adding a delay (waitForIdleSync() and/or waitForActivity()) did NOT seem to solve my problem. How do i force the orientation to landscape in my test, while still being able to find the fragments using findFragmentById()?

    Read the article

  • Can anyone help why my mockery doesn't work?

    - by user509550
    The test call real method(service) without mocking some expecations @Test public void testPropertyList() { Credentials creds = new Credentials(); creds.setUsername("someEmail"); creds.setPassword("somePassword"); creds.setReferrer("someReferrer"); final Collection<PropertyInfo> propertyInfoCollection = new LinkedList<PropertyInfo>(); final List<ListingInfo> listings = new ArrayList<ListingInfo>(); listings.add(listingInfoMock); listings.add(listingInfoMock); propertyInfoCollection.add(new PropertyInfo("c521bf5796274bd587c00bec80583c00", listings)); MultivaluedMap<String, String> params = new MultivaluedMapImpl(); params.add("page", "5"); params.add("size", "5"); instance.setPropertyListFacade(propertyListFacadeMock); mockery.checking(new Expectations() { { one(propertyListFacadeMock).getUserProperties(); will(returnValue(propertyInfoCollection)); one(listingInfoMock).getPropertyName(); allowing(listingInfoMock).getThumbnailURL(); one(listingInfoMock).getListingSystemId(); one(listingInfoMock).getPropertyURL(); one(listingInfoMock).getListingSystemId(); one(listingInfoMock).getPropertyURL(); } }); instance.setSessionManager(dashboardSessionManagerMock); testSuccessfulAuthenticate(); ClientResponse response = resource.path(PROPERTIES_PATH).queryParams(params).accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(200, response.getStatus()); mockery.assertIsSatisfied(); }

    Read the article

  • Can I write a test without any assert in it ?

    - by stratwine
    Hi, I'd like to know if it is "ok" to write a test without any "assert" in it. So the test would fail only when an exception / error has occured. Eg: like a test which has a simple select query, to ensure that the database configuration is right. So when I change some db-configuration, I re-run this test and check if the configuration is right. ? Thanks!

    Read the article

  • Using Tyburn with Maven

    - by TheDelChop
    Guys, I"m trying to use Tyburn to do some BDD with JBehave and I've got a question about what Tyburn can do. Can Tyburn simulate Menu selections? Like Ive I want to say something like @Then("when I select 'Start' from the Recording Menu) selectMenu(Recording) selectMenuItem(Start) Is there a way to make this happen? Thanks, Joe

    Read the article

  • How to use @BeforeClass and @AfterClass in JunitPerf?

    - by allenzzzxd
    Hi, I want to do some actions before the whole test suite (also after the suite). So I wrote like: public class PerformanceTest extends TestCase { @BeforeClass public static void suiteSetup() throws Exception { //do something } @AfterClass public static void suiteSetup() throws Exception { //do something } @Before public void setUp() throws Exception { //do something } @After public void tearDown() throws Exception { //do something } public PerformanceTest(String testName){ super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); Test testcase1 = new PerformanceTest("DoTest1"); Test loadTest1 = new LoadTest(testcase1, n); Test testcase2 = new PerformanceTest("DoTest2"); Test loadTest2 = new LoadTest(testcase2, n); } public void DoTest1 throws Throwable{ //do something } public void DoTest2 throws Throwable{ //do something } } But I found that it never reach the code in @BeforeClass and @AfterClass. So how could I do to solve this problem? Or is there other way to realize this? Thank you for your help.

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >