title,body,link,tags,view_count,is_answered,score,answer_count,critical points
TestRestTemplate vs WebTestClient vs RestAssured : What is the best approach for integration testing of Spring Boot Rest API,"<p>Which of the 3 APIs: TestRestTemplate, WebTestClient, RestAssured  is the most efficient for integration testing of Spring Boot Rest API (non-reactive) with respect to the following:</p>

<ol>
<li>Ensures compatibility with Spring boot for incremental versions.</li>
<li>Easy-to-use and extensive assertions for checking status codes, headers, both JSON/XML payload validation, response time, etc.</li>
<li>Has the possibility to test spring container configuration.</li>
<li>Features to reuse specific checks across all end points.</li>
<li>Is the most stable and therefore an Industry common practice.</li>
</ol>

<p>Few initial findings which sort of prevent one of them to be marked as clear winner are:</p>

<ul>
<li><p>TestRestTemplate &amp; WebTestClient are Spring built-in APIs so are auto-configurable with Spring Boot. Latest versions of RestAssured (4.0.0 onwards) can    have problems with spring    boot(<a href=""https://stackoverflow.com/questions/44993615"">java.lang.NoClassDefFoundError: io/restassured/mapper/factory/GsonObjectMapperFactory</a>)    and require explicit dependencies addition.</p></li>
<li><p>WebTestClient (a Fluent API) seems to have nice and easy to use syntax as compared to TestRestTemplate but is very new and there are    not enough examples showing its usage for non-reactive Rest APIs and    availability of extensive assertion API</p></li>
<li><p>RestTemplate (API on which TestRestTemplate is based) will be deprecated in future Spring Boot version.</p></li>
</ul>

<p>Feedbacks from experienced developers will be a great help.</p>
",https://stackoverflow.com/questions/61318756/testresttemplate-vs-webtestclient-vs-restassured-what-is-the-best-approach-for,"['spring-boot', 'rest', 'testing']",3413,TRUE,9,2,WebTestClient/TestRestTemplate/RestAssured APIs are suggested for integration testing of SpringBoot API
Junit and Integration Tests best approach,"<p>I want to make some integration test to test my whole program (it's a standart command line Java application with program args)</p>
<p>Basically I have 3 tests : one to create a resource, one to update the resource and finally one to delete it.</p>
<p>I could do something like this :</p>
<pre><code>@Test
public void create_resource() {
    MainApp.main(new String[] {&quot;create&quot;, &quot;my_resource_name&quot;});
}

@Test
public void update_resource() {
    MainApp.main(new String[] {&quot;update&quot;, &quot;my_resource_name&quot;});
}

@Test
public void delete_resource() {
    MainApp.main(new String[] {&quot;delete&quot;, &quot;my_resource_name&quot;});
}
</code></pre>
<p>It works... as long as the methods are executed in the correct order. I've heard that the good execution of a test should not depend of the order.</p>
",https://stackoverflow.com/questions/72534711/junit-and-integration-tests-best-approach,"['java', 'testing', 'junit', 'integration-testing']",228,TRUE,0,1,"Order of tests can be determined when writing the tests (could be important when performing integration testing on db)
Junit is also mentioned"
Laravel best approach for Testing if a value will change,"<h3>The code</h3>
<p>I have a database, which has a table for Teams and Instructors along the lines of:</p>
<pre><code>| id | team_id | instructor_id | ... |
</code></pre>
<p>Every 24 hours a batch runs that updates the instructor for that team.<br>
What I need to create is a simple Test to check if the batch is running properly, and the instructor is changed.<br></p>
<h3>The Issue</h3>
<p>The batch updates the instructor <strong>randomly</strong>, meaning that the same instructor might get chosen twice, throwing an error when running the test. I tried checking if the <code>updated_at</code> column changes, but it seems like when the same values are passed to <code>update()</code> Laravel does not change said column.</p>
<h3>The question</h3>
<p>How am I supposed to check if the instructor changes?<br>
I am only assigned to making the test, so I should not change the way the batch operates (like forcing it so that <code>updated_at</code> changes)<br>
However making a for loop until the instructor is changed looks very ugly.<br>
And since there are only between 3 to 5 instructors, the chances of the same instructor being picked a few times in a row is not that low.<br></p>
<h2>Update</h2>
<p>Here is the code as requested.<br>
The test file:</p>
<pre><code>class InstructorSelectionOrderTest extends TestCase
{
    use RefreshDatabase;

    ...

    /**
     * @test
     * @group instructorSelection
     *
     * @return void
     */
    public function test_old_team_instructor_random()
    {
        $team = factory(RoutineTeam::class)-&gt;create(['instructor_id' =&gt; 4, 'updated_at' =&gt; Carbon::now()-&gt;subDays(1)]);
        $room = factory(Room::class)-&gt;create(['team_id' =&gt; $team-&gt;id]);

        $this-&gt;createNewUser($team-&gt;id, $room-&gt;id);

        $this-&gt;artisan('project:reassign_instructors')-&gt;assertExitCode(0);

        $result = RoutineTeam::where('id', $team-&gt;id)-&gt;get();

        $this-&gt;assertFalse($result[0]-&gt;updated_at == $team-&gt;updated_at);
    }
</code></pre>
<p>The batch:</p>
<pre><code>class ReassignInstructors extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'project:reassign_instructors';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //list of rooms that needs to be updated
        $routineTeams = RoutineTeam::openedRoomTeams();

        ...

        foreach ($routineTeams as $routineTeam) {
            //Instructor::getRandomInstructor()-&gt;id = random number from 1 to 4
            $routineTeam-&gt;instructor_id = Instructor::getRandomInstructor()-&gt;id;
            $routineTeam-&gt;save();
        }

        return 0;
    }
}
</code></pre>
<p>The RoutineTeam table:</p>
<pre><code>| id | team_id | instructor_id | ... | updated_at
</code></pre>
<p>The test currently has a 25% chance of failing. I can only edit the test file. Is there a way to make it a 0% chance of failing only by changing the test file?</p>
",https://stackoverflow.com/questions/71838345/laravel-best-approach-for-testing-if-a-value-will-change,"['laravel', 'testing', 'optimization', 'updates']",196,TRUE,0,1,Adding constraints to testing data 
Best approach to test several similar classes in spock test?,"<p>I have a lot of similar classes (actually it is different types of events with one parent class). It is about 30 classes already and the number will be growing. Every class has its own logic to process, but there several fields that are exists in every class. I want to be sure every event's flow is taking care of common fields. It is become more complex, because of adding new event types and adding new flows. The best approach will be to create some dynamic test that will be checking common fields are processed. Saying 'dynamically' I mean the ability of the test automatically discover new classes and put them into the test pack. We are using spock, but it is not possible to dynamically generate 'where' section of test. I come with quite a strange approach that is not working, but illustrate my idea:</p>
<pre><code>def &quot;dynamic test&quot;() {
    given:
        def classes = methodToGetListOfEventClass()

    when:
        for(Class clazz : classes) {
                    ParentEvent event = clazz.getDeclaredConstructor().newInstance() as ParentEvent
                    service.sendEvent(event)
                }
            }

    then:
        for(Class clazz : classes) {
                    ParentEvent event = clazz.getDeclaredConstructor().newInstance() as ParentEvent
                    1 * sendExternalEvent(&quot;someId&quot;, event.getClass().getName(), Collections.emptyMap())
                    //check common fields exists
                    }
                }
            }

}
</code></pre>
<p>So I just try to create an instance of every class, pass it into the event handler and check created external event has all common fields set. It looks ugly and does not work. Is any suggestion on how to implement such a dynamic test?</p>
",https://stackoverflow.com/questions/71631373/best-approach-to-test-several-similar-classes-in-spock-test,"['java', 'testing', 'groovy', 'spock']",293,TRUE,0,1,Using dynamic data pipes to run multiple tests that are similar
The best approach to get the element in Java,"<p>There is an e-commerce site. Every day when they run the program, it has to return the featured product. Featured product is the most sold product of the day. In case if there are two or more products are identified as featured products then the method should sort them alphabetically and then return the last item.</p>
<p>For example</p>
<pre class=""lang-java prettyprint-override""><code>input_Products = [”redpencil”, “greenpencil”, “redpencil”, “yellowpencil”, “yellowpencil”]
</code></pre>
<p>For the given input the output should be returned as <code>yellowpencil</code>.</p>
<p>Below is my approach to the method called <code>getFeaturedProduct()</code> is below</p>
<pre class=""lang-java prettyprint-override""><code>public static String getFeaturedProduct(List&lt;String&gt; items) {
   int length = items.size();
   Map&lt;String, Integer&gt; map = new HashMap&lt;String,Integer&gt;();

   for(int i=0; i&lt;length; i++)
   {
       String prod = items.get(i);
       if(map.containsKey(prod))
       {
           map.put(prod, map.get(prod)+1);
       }
       else
           map.put(prod, 1);
   }

   int maxPurchasedItem = Collections.max(map.values());
   System.out.println(&quot;Max Purchased Item : &quot; + maxPurchasedItem);

   List&lt;String&gt; prodNames = new ArrayList&lt;&gt;();
   for(Map.Entry&lt;String, Integer&gt; entry :map.entrySet())
   {
       if(entry.getValue() == maxPurchasedItem)
       {
           prodNames.add(entry.getKey());
       }
   }

   Collections.sort(prodNames);
   System.out.println(&quot;the featured item is : &quot;+ prodNames.get(prodNames.size()-1));
   return prodNames.get(prodNames.size()-1);
}
</code></pre>
<p>Could you please tell me is this the best approach to proceed? What is the time complexity of this approach?</p>
",https://stackoverflow.com/questions/70059874/the-best-approach-to-get-the-element-in-java,"['java', 'selenium', 'testing', 'data-structures', 'ui-automation']",95,FALSE,0,1,"Algorithm complexity discussed, not relevant for this research"
What is the best approach for Automation End To End Testing in an ETL Project?,"<p>We have an ETL Project wherein Data from one UI application flows down in a series of applications(Transformation/Logic).</p>
<p>The overall motto is to see the data of 'UI 1' in 'UI 2'.
'Spring Java Server 1' calls the API of UI1 Server and the data gets flow into different servers and persisted in the database. A script also persists some data in the database.
'UI 2 with Backend server' gets the data from database and show it in the UI.</p>
<p><a href=""https://i.stack.imgur.com/DpCQP.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/DpCQP.png"" alt=""enter image description here"" /></a></p>
<p>Now the question,
I am looking for the best possible way to perform E2E testing.
We'll start by triggering 'Spring Java Server 1' which calls APIs of 'UI 1 with BackendServer 1' and at the end using selenium see the data in 'UI 2'.</p>
<p>I am thinking about creating a separate Java Application with UI just for testing which triggers the 'Server 1' and with selenium verifies the UI2
But the problem is with Script. After the database, we have to manually run script and then wait for it to complete. How we can automate manually running the script with some kind of state Management?</p>
<p>Please suggest more on the architecture of E2E  or how can i enhance this E2E setup. And what tools/framework i can use.</p>
",https://stackoverflow.com/questions/63735864/what-is-the-best-approach-for-automation-end-to-end-testing-in-an-etl-project,"['java', 'testing', 'automated-tests', 'integration-testing', 'end-to-end']",338,FALSE,0,1,Question regarding automation of end-to-end testing. Powershell was suggested for running scripts
"What is the best approach to test a HapiJS plugin, with Lab?","<p>What is the best way to test a HapiJS plugin, for example one plugin that add routes and handlers.</p>

<p>Since I have to create an instance of Hapi.Server to run the plugins, should I define all the tests from the app's root, for all the plugins ? </p>

<p>or </p>

<p>should I manage to get THE instance of Hapi.Server in my plugin's local tests ?</p>

<p>If I go for the second option, my server will have registered all the plugins, including those that the plugin to be tested doesn't depends on.</p>

<p>What is the best way to approach this ?</p>

<p>Thanks in advance.</p>
",https://stackoverflow.com/questions/44199580/what-is-the-best-approach-to-test-a-hapijs-plugin-with-lab,"['testing', 'hapi.js', 'lab']",918,TRUE,2,1,Content of this post is irrelevant for this research
"What could be best approach for regression suite for microservices, Can Scala be used for that?","<p>I was asked to prepare a regression suite for testing micro-services, for that I need to:
- Run scripts
- Run different API's (can be multiple for scenarios to be used in next API)
- Publish result in some presentable format</p>

<p>My own first choice was Jmeter for this, but senior resource didn't agreed and I was asked to use SCALA, while working with Scalatest , I am stuck with Futures as most of my testing revolves around calling Restful API's.</p>

<p>I still think Jmeter is better for what I am doing, but don't have solid base for that, can anyone suggest which one I should go for?</p>
",https://stackoverflow.com/questions/42711241/what-could-be-best-approach-for-regression-suite-for-microservices-can-scala-be,"['scala', 'testing', 'junit', 'jmeter', 'scalatest']",357,TRUE,0,2,scalatest used for regression testing
Best approach when testing REST Endpoints,"<p>I'm looking at the following code which tests a REST Endpoint:</p>

<pre><code>Response response = server.newRequest(""/myresource"").request().buildPost(Entity.text(""42"")).invoke();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
MyModel myModel = response.readEntity(MyModel.class);
assertEquals(42, myModel.getResult());
</code></pre>

<p>as outlined here:</p>

<p><a href=""https://dzone.com/articles/how-test-rest-api-junit"" rel=""nofollow noreferrer"">https://dzone.com/articles/how-test-rest-api-junit</a></p>

<p>I'm wondering though is it best to convert the response to a MyModel object and apply the tests on this object. I would be more inclined to do this: </p>

<pre><code>JSONObject expectedResponse = new JSONObject();
expectedResponse.put(""name"", ""mkyong.com"");
expectedResponse.put(""age"", new Integer(100));

assert(response, expectedResponse);
</code></pre>

<p>Which approach is best?</p>
",https://stackoverflow.com/questions/42577460/best-approach-when-testing-rest-endpoints,"['java', 'rest', 'testing']",78,FALSE,1,0,best approach to test REST endpoints
Test an application GUI coded with Java Swing : best approach?,"<p>I have to automatically generate test for a Java ""drawing"" application GUI (like ArgoUML/LaTeXDraw/etc). I need to verify that the tested application behave correctly. In my given example, I need to check that the Undo/Redo buttons works well = Undo put the canvas in the predecessing state and Redo put it again in the state it used to be.</p>

<p>I have already an idea of how I will approach the problem but I would like feedback of experienced people:</p>

<ul>
<li>Should I use the Robot class to simulate the inputs onto the GUI? Or
is there an easier way?</li>
<li><p>I need to capture the state of the program for later analysis to see
if the state of the program is consistent, should I just screenshot
the window or is there a way to iterate through all the JFrame's
components and capture their properties (it should include canvas
state)?</p></li>
<li><p>More importantly, I do not know how to locate each button on the
interface. What is the simplest way to tell the Robot that a given
button is at a certain (x, y) position in the window? Should I search
the pixels in a .jpeg version of the button? Should I locate each
button on the interface manually (i.e. create a class for each button
containing x, y attributes)?</p></li>
<li>And finally, I have never ""attached"" a Robot to a given program. Can
I just load the .jar file of the software I want to test and tell
Robot to operate on that window? Or do I need to work with all the
source files from the original project?</li>
</ul>

<p>Thank you for your time, if any part of my question seems not clear enough please tell me and I will try to explain it even more clearly.</p>

<p>P.S: any advice concerning the work I need to do is welcome :)</p>
",https://stackoverflow.com/questions/41523541/test-an-application-gui-coded-with-java-swing-best-approach,"['java', 'swing', 'user-interface', 'testing']",285,TRUE,0,2,GUI testing and automated tests. Replies can't be generalized for all of GUI testing
Which is the best approach to isolate tests on universal iOS apps?,"<p>I'm working on an universal iOS project and my goal is to add as many useful tests that I can. I'm stuck in a point where I have a different behavior between the iPhone and iPad versions and I would like that some tests run only on a specific version. For instance, since the iPhone screen is much smaller than the iPad some buttons will be replaced by an ActionSheet. That said, I would like to know which is the best way to isolate those tests.</p>

<p>My first idea was to create a specific test target for each device, however I think this solution would make it harder to understand what is being tested in general. My current solution for this is to check the device, on each test case, before running the test and skip it if necessary.</p>
",https://stackoverflow.com/questions/34280490/which-is-the-best-approach-to-isolate-tests-on-universal-ios-apps,"['ios', 'xcode', 'testing', 'automated-tests', 'ios-universal-app']",49,FALSE,1,0,How test an application on different devices?
Reuse of automated integration tests: choose best approach,"<p>We have a complex system, shown in the diagram below, consisted of 3 interacted systems: A, B and C. Each system has own database, services and UI layers. Systems communicate via HTTP protocol.</p>

<p><img src=""https://i.stack.imgur.com/X6xAN.jpg"" alt=""complex system&#39;s component diagram""></p>

<p>Basic work-flow of complex system is following: user creates deal in system A, which stores deal in its own database and pushes it to the system B. In the system B deal is validated and stored in its own database. User can view, edit and manage deal’s entitlements with UI of system A as well as with UI of system B. System C periodically pulls data from system B and again stores it in its own database. Finally, user can view deals with UI of system C.</p>

<p>We assume that systems A, B and C are covered by separate automated integration tests. These systems are developed by different teams (but of the same company), have separate code bases and use different languages (Java, C#). The task is to create automated end-to-end service-layer tests (also so-called <a href=""http://martinfowler.com/bliki/SubcutaneousTest.html"" rel=""nofollow noreferrer"">Subcutaneous Tests</a>) for whole complex system. Selected language for tests is C#.</p>

<p>Here is simplified example of end-to-end test scenario which needs to be automated:</p>

<ul>
<li>User creates deal in system A</li>
<li>User searches for created deal with system B’s UI and ensures that deal is found</li>
<li>User searches for created deal with system C’s UI and ensures that deal is NOT found</li>
<li>User changes deal’s entitlements with system A’s UI</li>
<li>User searches for created deal with system B’s UI and ensures that deal is found</li>
<li>Entitled user searches for created deal with system C’s UI and ensures that deal is found</li>
<li>Non-entitled user searches for created deal with system C’s UI and ensures that deal is NOT found</li>
</ul>

<p>So far there are 2 approaches to creating automated end-to-end tests suggested by members of our team:</p>

<ol>
<li>To reuse existing automated integration tests of particular systems in end-to-end tests. For this purpose special framework is supposed to be created which will play role of “orchestrator” that is: run tests for particular systems in appropriate order and manage data exchange between them. In this case tests of course need to be aware of custom framework.</li>
<li>To create automated end-to-end tests for complex system independently from existing integration tests for particular systems. Each test is supposed to be self-contained and can be run in arbitrary order by general-purpose test runner (i.e. XUnit). In doing so reuse of existing test’s code of course is desirable where it is possible.</li>
</ol>

<p>Please help us to choose between approaches described above or suggest different ones.</p>
",https://stackoverflow.com/questions/30423954/reuse-of-automated-integration-tests-choose-best-approach,"['testing', 'automated-tests', 'integration-testing', 'end-to-end']",281,FALSE,1,0,"Automating end-to-end tests, no answer given"
