Jtest code in eclipse

subratdash8subratdash8 Posts: 24

Hi,
I have generated test class using jtest IDE.
I want to run this code in my normal eclipse editor
How to do that?
How to use this sonarqube?

Best Answers

  • Andrey MadanAndrey Madan Posts: 174 ✭✭✭
    Accepted Answer

    @subratdash8 : Which JTest version are you using? This is a very important piece of information we need to determine your next steps. Second question is what is the purpose of using SonarQube here? Display of test results and coverage in a dashboard? Correct?

  • subratdash8subratdash8 Posts: 24
    Accepted Answer

    Hi @Andrey Madan
    I think it's 9.3.
    In our project currently we r using sonarqube to display code coverage and tesr case success rate to client.Recently we have started using JTest.
    So can we do that?
    Thanks in advance :smile:

  • Andrey MadanAndrey Madan Posts: 174 ✭✭✭
    Accepted Answer

    @subratdash8 : JTest 9.3 is a pretty old version. If you generate tests using this version, you will have to use older maven/ant plugins to integrate with CI/CD process. How far have you advanced in using the JTest 9.3? JTest 9.x product line is not designed to submit data to SonarQube.
    The good news, the new JTest line of products which is giving you ability to not only create pure JUnits but also easily integrate with your CI/CD pipeline and publish results to a more advanced reporting and analytics ecosystem (DTP). Check out this awesome blog post from @Mark Lambert : https://blog.parasoft.com/why-people-hate-unit-testing-and-how-to-bring-back-the-love :). If you have further questions after reading and listening to the blog video, please contact your friendly Parasoft representative.

  • jakubiakjakubiak Posts: 307 ✭✭✭
    Accepted Answer

    Jtest 9 builds test cases that require Jtest libraries in order to run. It does not build test cases that use Mockito. Instead if you switch to Jtest 10, then you will be able to build maintainable test cases that run on their own without any Parasoft dependencies. The test cases built by Jtest 10 use Mockito for mocking.

Answers

  • subratdash8subratdash8 Posts: 24

    @Andrey Madan thanks..
    But I have one doubt. After generating test classes in jtest IDE can I use same code in junit class in normal eclipse IDE.
    Currently we are using mockito framework to mock data service or any dependency call.In jtest I can see the stup is getting created for that call.
    But how to integrate this functionality in junit after creating stub code in jtest editor.
    Thanks in advance. :smile:

  • subratdash8subratdash8 Posts: 24

    @jakubiak
    Thanks..
    Can we use jtest library in junit test class??
    Thanks in advance. :smile:

  • Andrey MadanAndrey Madan Posts: 174 ✭✭✭

    @subratdash8 : It's just a library, so yes. However, I would strongly recommend upgrading to JTest 10 and Unit Test Assistant. The test cases created by UTA will be much easier integrated with your workflow (CI / Mockito, etc). You WILL save yourself a lot of headaches down the road.

  • jakubiakjakubiak Posts: 307 ✭✭✭

    Do you mean to ask if you can use the Jtest 9 library in a JUnit test class when running in an IDE that does not have Jtest installed? I would suspect it is possible but I have not done it so I don't know how easy or if it is actually possible.

    Do you have existing test cases built with Jtest 9? Or are you just starting out in building test cases? Because if you are just starting out, you really want to use Jtest 10 - the test cases are MUCH cleaner and can be run independently of Parasoft.

  • maciekgmaciekg Posts: 14
    edited August 2017

    Using Jtest 9.x library for test case execution.
    Generally, I could say that You need Jtest tool to correctly execute these test cases. These test cases are using few features like parameterization, stubs and other utilities to realize some functionality and should be executed by Jtest tool.
    Also Jtest tool is use to provide information about coverage.

  • subratdash8subratdash8 Posts: 24

    @jakubiak
    When you are saying jtest 9 or 10,what does it mean?
    It means only library like jar or it's version of editor that is used for jtest.
    Currently I am using parasoft jtest editor for that.
    I am confused what is actually jtest means.
    :neutral:

  • subratdash8subratdash8 Posts: 24

    @maciekg
    Thanks.
    Currently we are using maven and sonarqube for build and report generation to show code coverage.
    I don't have idea how to use this with jtest.
    I am new to this thing.
    Any pointers would be helpful for me.

  • maciekgmaciekg Posts: 14

    By saying Jtest 9 vs 10 we say about tool - whole plugin to IDE.

    Jtest 9 was delivered only as plugin to Eclipse.
    Jtest 10 is devliery as pluign to Eclipse, IntelliJ or Netbeans.

    jtest.jar - is only small library which realize extra features in test cases generated by Jtest.

  • subratdash8subratdash8 Posts: 24

    Hi All,
    Finally I got jtest 10 version.. I am exploring its feature. One issue that I have noticed is
    For EJB object it is not creating stub method by itself. So it's initial with null
    So is it not possible for jtest to mock ejb object and if it is possible how to do that?
    Waiting for you response..

  • bmcglaubmcglau Posts: 8

    Depending on which action you used to create the test with Unit Test Assistant, objects like EJBs may not be instantiated by default. This gives you the opportunity, when building tests, to decide whether you want a real object or a mock in the test.

    If you select the local variable in the code editor, you can either instantiate it (using a constructor or factory method) or mock the object (using Mockito) using an action in the Unit Test Assistant view.

  • subratdash8subratdash8 Posts: 24

    Hi @bmcglau
    Thanks for your response. But as per jtest documentation if there is any other module call exist to do isolate test jtest will automatic mock dependent class objects.
    So why we can't do in case of EJB?
    Correct me if I am wrong.

  • subratdash8subratdash8 Posts: 24

    Hi @bmcglau
    Thanks for your response.
    When I am trying to create junit for 1 method I can see only 1 test methods getting formed. Buy we have different scenarios. So as per my understanding jtest should create junit based on different scenarios not only 1 method to cover only 1 scenario.
    Correct me if I am wrong *

  • bmcglaubmcglau Posts: 8

    Hi @subratdash8,

    In Jtest 9.x, generating tests did build multiple test methods for each method-under-test; with Jtest 10.x, we have moved away from this paradigm because it often resulted in incorrect and un-maintainable tests. Unit Test Assistant is designed to provide a guided test-creation workflow, where developers define the scenarios they need for each method. We have found that in nearly all cases, a using the guided test creation paradigm results in better, more maintainable tests than the all-automatic approach.

    I would also recommend reaching out directly to our support team or a Parasoft representative - we would be happy to take a closer look at what you are trying to accomplish and help you get there.

  • subratdash8subratdash8 Posts: 24

    Hi @bmcglau
    Thanks for your response.. I am arranging a meeting with jtest team. Before that I am just clarifying some open point so that I can explain to my team.
    So can we mock this type of object like ejb or if we are calling methods of different class then mocking of that function call part, by jtest instead manually after creating test methods.?
    I mean can we ask jtest to mock one class or one function call after its created jtest method?
    The answer to this question will solve our many doubts.
    Thanks in advance

  • bmcglaubmcglau Posts: 8

    Hi @subratdash8 ,
    Yes, you can mock an EJB and its methods. If you select a local variable that is initialized to null, you can use the Mock it action to instantiate the EJB as a mock. Alternatively, you can use Deep Setup to automatically mock the EJB and any method calls being made to it from the method under test.

    When tests are run, UTA will make recommendations for each method call on the mocked EJB, if the method is not yet mocked. There is a quick-fix link in the recommendation to automatically mock the method.

    Be sure to read the documentation on mocking here: https://docs.parasoft.com/display/JTEST1033/Creating+Mocks

  • subratdash8subratdash8 Posts: 24

    Hi @bmcglau
    I have read that documentation. But I can't see that mock option in recommendation tab. And there is only option for mockito. Power mockito option i cant see in preference. I can only see mock it option for getter and setter methods.
    And EJB object is initialized with null which is resulting in null pointer exception.
    Is any configuration missing from ur side?

  • jakubiakjakubiak Posts: 307 ✭✭✭

    Hi @subratdash8,
    As suggested by @bmcglau, I would recommend you contact our support team as it looks like we are having a hard time understanding your use case on the forums. With that being said, here are some quick thoughts:

    • PowerMockito support was added in version 10.3.3 - what version are you using? Please note that the PowerMockito option appears under the Parasoft > Unit Test Assistant > Mocking preferences.
    • Quick fixes to add mocking for specific methods happens when your test already has a mocked object defined, and there are methods being called on that object for which there are no mocks configured.
    • If the EJB is initialized to null, then you can manually configure it to be initialized to something non-null. Unit Test Assistant has actions in the Unit Test Assistant view to help you with instantiating it. However, it's hard to explain exactly what Unit Test Assistant is doing, and how to work with it better, without seeing your exact use case. So please contact support, or consider posting sample code and the test that gets generated from it here.
  • subratdash8subratdash8 Posts: 24

    HI Everyone,
    We have installed 10.3.4 jtest. Now we are able use power mockito feature and we can mock static method. But there is still some issue.
    1.we are not able to still mock EJB object in this version. and if we are manually mocking EJB object still we can not see any recommendation to mock the function call made by that object.
    2.If we are using list of some data and we are passing to source method then after creating test method by jtest , we can see that Jtest is only creating a empty list without any content. So is it a expected behaviour and we need to add content or something is missing from our side
    3.If code contains some if else condition based on some scenario then Jtest is not covering all scenario.In this case do we need to manual modify value to cover all condition?

    Please let me know in case you need more details

    Thanks in advance

  • bmcglaubmcglau Posts: 8

    Hi @subratdash8 ,
    Regarding the EJB mocking issues, I would recommend contacting and working with our support team to look into the issue further. Perhaps there is something in your EJB or related code which we need to understand in order to provide a better answer.
    By default, Unit Test Assistant instantiates collections as empty lists and maps as empty HashMaps. This is expected behavior.
    Jtest does not currently analyze code branches to drive test creation. As the test developer, you would configure the test to take the code branches that you want it to take, in order to test a specific code-path.

  • subratdash8subratdash8 Posts: 24
    edited February 22

    Hi @bmcglau and all
    Thnaks for your response. I have raised thia concerns to my tool team and they will contact jtest team soon.
    So now coming to list or map initialization and branch coverage..
    1.In jtest 10.3.2..we saw its creating mock of list or map.. And 10.3.4, it is creating a empty list and map.. So can we expect this feature in higher version.. Where jtest will analyze the list and it will add mock objects into that. This feature is basically required when list contains a user defined class with lot of properties and our functions invocation depend on this data.. So if jtest can analyze this and create mock 9f objects with some mock data and add it to list then it will reduce some more efforts given by developers.

    2.And same as for conditional scenarios also.. If higher version includes this..
    Waiting for your input and suggestions..
    Thanks

  • bmcglaubmcglau Posts: 8

    Hi @subratdash8 ,
    Yes, we intentionally changed our default instantiation of Collections and Maps (including Lists) to use concrete classes like ArrayList and HashMap instead of mocking them. This is because, in nearly all circumstances, the List or Map is not the object which needs to be mocked. However, when we generate tests we don't necessarily know what data you - the developer - want in the collection. In some tests, you probably want an empty collection, and in others you may want nulls or real objects, depending on the scenario you want to test. Instead of generating too much code (which quickly becomes unmanageable), we opted to initialize empty collections, and expect the developer to populate the collection. I should mention that you can easily create a local variable for an item in the list, and use UTA actions to instantiate or mock the item.
    We do eventually want to make improvements to UTA in which we are able to analyze code branches to generate more complete "deep setup" tests.

  • subratdash8subratdash8 Posts: 24

    Hi @bmcglau
    Thanks for you feedback.
    But one point i want to mention here.
    While creating test methods jtest is mocking al input l parameters. While writing test methods may be developer need empty or null or with some data added into the list.
    But anyhow we need to test scenarios where input list to function have at least one data or object for further operation which is more important in testing.
    So if jtest can create mock objects with mocking parameters and add into the list then later developer will write for null or empty.
    So if you can include at least one mock object in list then developer wll try for other scenarios in higher version of jtest then it will add new flavor.

    And for 2nd point waiting for new version of jtest f for condition coverage.

    Thanks

  • jakubiakjakubiak Posts: 307 ✭✭✭

    Hi @subratdash8, thank you so much for your feedback. The suggestions that you are making directly relate to internal discussions we are having about how to make the created tests get better coverage. I have captured your feedback and we will use it as input to our decisions about what to do in the next release. I can't promise that we will include everything you are asking for in the next release - but we are working in this area and there will be improvements.

  • subratdash8subratdash8 Posts: 24

    Hi I have attched scrrenshot related to EJB Mock. Currently we are not able to mock EJB Object.

    Jtest is not mocking object which is being formed by EJB annotation not even in recommendation I can see that mock it option.

    Can anyone please have a look and let me know what is the issue?

    Let me know if any more details required

    Regards,
    Subrat

  • subratdash8subratdash8 Posts: 24

    Can anyone please help me out on above issue?

  • jakubiakjakubiak Posts: 307 ✭✭✭

    Jtest does not currently have explicit support for the EJB annotations that are being used in your examples. However, Jtest Unit Test Assistant can still be useful for creating and updating tests even if it does not have specific support for a particular technology. I see from internal channels that you have filed a support case with Parasoft - we will be reaching out to you via our support team to set up a meeting with you to go through the specifics of your use case and how Jtest Unit Test Assistant can help you.

  • subratdash8subratdash8 Posts: 24

    Thanks @jakubiak for your response.
    So I am wondering if we will create mock ejb object manually and execute the source method, so does jtest figure it out and provide recommendation to mock the function call made by that particular EJB mock object?

    If that is possible then it can resolve our issue?

    Waiting for your response.
    Thanks in advance. :smile:

  • maciekgmaciekg Posts: 14
    edited March 13

    Hi Subrat

    There is no difference between mocks constructed by Jtest automatically and mocks created by user manually. If you are using same mock framework writing them manually or Jtest assist actions to make them semi-automatically.
    Next during execution if Jtest detect interaction with mock - it will catch this and propose for you mock methods used during test scenario. This way finalize control over test case.
    Please try to verify this in your case.
                                                                                                 regards Maciek
    
  • subratdash8subratdash8 Posts: 24

    HI @maciekg @jakubiak ,
    I have tried mocking ejb object by @mock annotation using mockito-all-1.10.19 lib provided by jtest itself.
    I can see while debugging ejb object is going as mock instance. and not as null.
    But jtest is not giving any suggestion for object which is mocked by @mock annotation.
    Instead of that the object which is being mocked by "mock(Class.class)", jtest is giving suggestion.
    So I think may be jtest is not able to idenitify the mocking that is done by annotation.
    I have attched acreenshot with code snippet. Please have a look and provide your feedback on same.
    Thanks,
    Subrat

  • subratdash8subratdash8 Posts: 24
    edited March 20

    Please find snapshot while debugging showing value of ejb object by mocking and other one after running test method by UTA showing recommendation.

    let me know if any more detail required

    Thanks,
    Subrat

  • subratdash8subratdash8 Posts: 24

    Hi all,
    Can anyone please provide the update on below query?

    Thanks
    Subrat

  • subratdash8subratdash8 Posts: 24

    HI @bmcglau ,
    Thanks a lot for your response. Is there any update, when we can expect higher version of UTA and what all new feature we can get in that version?
    We are in the way to use this tool in our existing project. We are really interested in Jtest. But unfortunately because of some limitation we are not able to roll out in our project yet. So I need update on Jtest so that I can inform my team on same and we can wait for this. :smile:
    Waiting for your response.
    Regards,
    Subrat

  • jakubiakjakubiak Posts: 307 ✭✭✭

    The main focus of our work for the next version is supporting IntelliJ within the Unit Test Assistant. There will also be some improvements in how the created test cases exercise different parts of the code under test. For more information on specific features or release dates, please contact your Parasoft representative. If you have specific requests for functionality that would help support your use cases, please connect with your Parasoft representative for that as well.

Sign In or Register to comment.