Jtest code in eclipse

subratdash8subratdash8 Posts: 11

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: 90 ✭✭
    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: 11
    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: 90 ✭✭
    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: 214 ✭✭✭
    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: 11

    @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: 11

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

  • Andrey MadanAndrey Madan Posts: 90 ✭✭

    @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: 214 ✭✭✭

    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: 7
    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: 11

    @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: 11

    @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: 7

    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: 11

    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: 5

    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: 11

    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: 11

    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: 5

    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: 11

    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: 5

    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: 11

    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: 214 ✭✭✭

    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.
Sign In or Register to comment.