title,body,link,tags,view_count,is_answered,score,answer_count
Undefined keyword: connect to database &amp; disconnect from database while doing database testing using robot framework,"<p>Settings:</p>
<pre><code>Library     OperatingSystem
Library     DatabaseLibrary


Suite Setup       Connect To DataBase       pymysql     ${DBName}    ${DBUser}    ${DBPass}    ${DBHost}    ${DBPort}
Suite Teardown    Disconnect From Database
</code></pre>
<p>Variables:</p>
<pre><code>${DBHost}         127.0.0.1
${DBName}         mydb
${DBPass}         root
${DBPort}         3306
${DBUser}         root
</code></pre>
<p>Test cases:</p>
<pre><code>Create person table
    [Tags]    db    smoke
    ${output} =    Execute SQL String    CREATE TABLE person (id integer unique,first_name varchar(20),last_name varchar(20));
    Log    ${output}
    Should Be Equal As Strings    ${output}    None
</code></pre>
<p>When I mouse hover on &quot;Connect to database&quot;, I get an error:</p>
<blockquote>
<p>Undefined keyword: connect to database
Create person table<br />
| FAIL |<br />
Parent suite setup failed:<br />
OperationalError: (2003, &quot;Can't connect to MySQL server on '127.0.0.1' ([WinError 10061] No connection could be made because the target machine actively refused it)&quot;)</p>
</blockquote>
",https://stackoverflow.com/questions/73516482/undefined-keyword-connect-to-database-disconnect-from-database-while-doing-da,"['python-3.x', 'database', 'robotframework']",127,False,0,0
Which is the well-suited framework to perform Api testing along with database testing in automation?,"<p>As per the client's requirement, I need to perform automation testing on API and database with selenium web driver using java and also need to verify the API response with DB data. So which framework will be well-suited to perform the automation testing on above mentioned? Your suggestion will be highly appreciable.</p>
",https://stackoverflow.com/questions/74065371/which-is-the-well-suited-framework-to-perform-api-testing-along-with-database-te,"['maven', 'selenium-webdriver', 'automation', 'rest-assured', 'database-testing']",32,False,0,0
get data Factory Relationships for Laravel Testing,"<p>according <a href=""https://laravel.com/docs/9.x/database-testing#factory-relationships"" rel=""nofollow noreferrer"">laravel-database-testing</a></p>
<p>I have a factory relationship for testing data, my code like this</p>
<pre class=""lang-php prettyprint-override""><code> public function test_users_can_authenticate_using_the_login_screen()
    {
        $this-&gt;seed(RoleSeeder::class);
        $data = Organization::factory()
            -&gt;count(1)
            -&gt;has(User::factory()-&gt;count(2), 'users')
            -&gt;create();

        $response = $this-&gt;post('/login', [
            'email' =&gt; $data-&gt;email,
            'password' =&gt; 'password',
        ]);

        $this-&gt;assertAuthenticated();
        $response-&gt;assertRedirect(RouteServiceProvider::HOME);
    }
</code></pre>
<p>How do I get the user-&gt;email data??, when i try <code>$data-&gt;email</code> or <code>$data-&gt;users</code> are not found?</p>
",https://stackoverflow.com/questions/71976586/get-data-factory-relationships-for-laravel-testing,"['php', 'laravel', 'laravel-testing']",167,True,1,1
laravel 8: how to use seeder in unit test,"<p>im trying to get the data after seeding a simple json to database. Here's the code:</p>
<pre class=""lang-php prettyprint-override""><code>&lt;?php

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use Database\Seeders\TagsSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;

class TagTest extends TestCase
{
    use RefreshDatabase;

    public function test_GetTags()
    {
        $this-&gt;seed(TagsSeeder::class);
        $response = $this-&gt;get('/api/tags')-&gt;seeJson([&quot;name&quot; =&gt; &quot;mytags&quot;]);
        $response-&gt;assertStatus(200);
    }
}
</code></pre>
<p>coding above based on documentation here: <a href=""https://laravel.com/docs/8.x/database-testing#running-seeders"" rel=""nofollow noreferrer"">database testing</a>
but when i run the test with command</p>
<pre class=""lang-bash prettyprint-override""><code>php artisan test ./tests/Unit/TagTest.php
</code></pre>
<p>it's return error below:</p>
<pre><code>Call to undefined method Tests\Unit\TagTest::seed()
</code></pre>
",https://stackoverflow.com/questions/73132531/laravel-8-how-to-use-seeder-in-unit-test,"['php', 'unit-testing', 'laravel-8', 'laravel-seeding']",721,True,0,1
mysqldump in .php file,"<p>What's wrong with the exec() function</p>
<pre><code>&lt;?php

exec('mysqldump --host=localhost --user=root --password=&quot;&quot; testing &gt; C:/Users/deleo/Desktop/newfile.sql');

?&gt;
</code></pre>
<p>when I run this code it's nothing happen but only white screen</p>
<p>I expected the output .sql file with my database(testing) table structure and data itself</p>
<p>When I did this</p>
<p>`</p>
<pre><code>&lt;?php
define(&quot;BACKUP_PATH&quot;, &quot;C:/Users/deleo/Desktop/&quot;);

$server_name   = &quot;localhost&quot;;
$username      = &quot;root&quot;;
$password      = &quot;&quot;;
$database_name = &quot;testing&quot;;
$date_string   = date(&quot;Ymd&quot;);

$cmd = &quot;mysqldump --hex-blob --routines --skip-lock-tables --log-error=mysqldump_error.log -h {$server_name} -u {$username} -p{$password} {$database_name} &gt; &quot; . BACKUP_PATH . &quot;{$date_string}_{$database_name}.sql&quot;;

$arr_out = array();
unset($return);

exec($cmd, $arr_out, $return);

if($return !== 0) {
    echo &quot;mysqldump for {$server_name} : {$database_name} failed with a return code of {$return}\n\n&quot;;
    echo &quot;Error message was:\n&quot;;
    $file = escapeshellarg(&quot;mysqldump_error.log&quot;);
    $message = `tail -n 1 $file`;
    echo &quot;- $message\n\n&quot;;
}
?&gt;
</code></pre>
<p>`</p>
<p>I got this error
<strong>mysqldump for localhost : tapsihannibhey failed with a return code of 1 Error message was: -</strong></p>
",https://stackoverflow.com/questions/74712028/mysqldump-in-php-file,"['php', 'mysql', 'backup']",45,False,0,0
How to disable JSON field type in H2?,"<p>I am doing database testing with <code>@SpringBootTest</code> with in-memory H2 database. I found, that <code>JSON</code> fields behave differently when created within <code>TestRestTemplate</code> and directly. The difference is not observed in <code>MySQL</code>. My fields are annotated with</p>
<pre><code>@Column(name = &quot;content&quot;, nullable = false, columnDefinition = &quot;JSON&quot;)
private String content;
</code></pre>
<p>I.e. database type is <code>JSON</code> while Java type is <code>String</code>. Sometimes the content of JSON is escaped, i.e. backslashes are added before quotes.</p>
<p>If I mark field with <code>TEXT</code> this doesn't happen.</p>
<p>The question is: how to make <code>H2</code> to ignore <code>JSON</code> field type?</p>
<p>Setting following URL causes error:</p>
<pre><code>spring.datasource.url=jdbc:h2:~/my_db;INIT=CREATE TYPE &quot;JSON&quot; AS TEXT;
</code></pre>
",https://stackoverflow.com/questions/72212740/how-to-disable-json-field-type-in-h2,"['mysql', 'json', 'spring-boot', 'hibernate', 'h2']",212,False,0,0
Use firebird database as data source in Power BI via ODBC,"<p>hope someone can provide some insights or experience in this area.
I am currently building some reports in Power BI, the data source is connected via ODBC to a firebird database (testing environment atm). I copied the script to SQL statement and it runs ok.
However, something went wrong every time I refreshed the data, it stops at 'loading data to model' stage. I have to end Power BI in task manager then restart it again.
I don't know why this happens.
Thanks in advance.</p>
",https://stackoverflow.com/questions/74176861/use-firebird-database-as-data-source-in-power-bi-via-odbc,"['sql', 'firebase', 'powerbi', 'odbc', 'report']",145,False,0,0
Can &quot;for&quot; relations in a laravel seeder use the child model?,"<p>I'm writing a seeder in which one model (<code>ProductVariant</code>) belongs to (many to one) other model (<code>Product</code>). For properly seeding all relations on the <code>Product</code>, I need to access the <code>ProductVariant</code> model. The Laravel documentation shows this is possible with the <code>-&gt;has()</code> function, but because of the nature of this relationship I need to use a <code>-&gt;for()</code>, which doesn't seem to work in the same way.</p>
<p>Below is the snipped of code I'm talking about and how I would expect it to work:</p>
<pre class=""lang-php prettyprint-override""><code>ProductVariant::factory()
    -&gt;for(
        Product::factory()
            -&gt;state(function (array $attributes, ProductVariant $productVariant) {
                dd(($attributes, $productVariant);
            })
    )-&gt;create();
</code></pre>
<p>Is there another way to do what I need it to do or am I missing something?</p>
<p>Documentation I'm referring to: <a href=""https://laravel.com/docs/9.x/database-testing#has-many-relationships"" rel=""nofollow noreferrer"">https://laravel.com/docs/9.x/database-testing#has-many-relationships</a></p>
",https://stackoverflow.com/questions/72616721/can-for-relations-in-a-laravel-seeder-use-the-child-model,"['php', 'laravel', 'eloquent', 'laravel-factory']",130,False,1,0
Is there a possibility of unit testing database functions using cmocka?,"<p>I am trying to make some unit tests for database functions in C language, but i am not aware is it possible with cmocka?
I couldn't find any example on the internet for database testing using cmocka, so i wonder if someone has an example of testing database functions with cmocka. For example it could be connecting to database, reading from database, writing to database, updating database, any example would help.</p>
<p><strong>EDIT</strong>
Let's say i have the following function in a separate Base.c file:</p>
<pre><code>static  void    dbclose(int SQLnumber)
    {

    if (hDbc[SQLnumber])
        {
        SQLDisconnect(hDbc[SQLnumber]);
        SQLFreeConnect(hDbc[SQLnumber]);
        }

    hDbc[SQLnumber] = NULL;
    }
</code></pre>
<p>How to define the wrap method in CMakeLists.txt so i could use it in Tests.c file?
Also, is it possible to wrap the SQLDisconnect and SQLFreeConnect from the SQL API separately?</p>
",https://stackoverflow.com/questions/73489914/is-there-a-possibility-of-unit-testing-database-functions-using-cmocka,"['c', 'unit-testing', 'database-testing', 'cmocka']",40,False,0,0
How to return a newly created record back from the database using gorm,"<p>I have a function that creates a new user, however the reccomended way to get the values of the user does not include the autogenerated values created by the database (id, created_at)</p>
<pre><code>type User struct {
    Id         string `json:&quot;id&quot; gorm:&quot;primaryKey&quot;`
    Email      string `json:&quot;email&quot;`
    Password   string `json:&quot;password&quot;`
    Created_At string `json:&quot;created_at&quot;`
    Updated_At string `json:&quot;updated_at&quot;`
    Deleted_At string `json:&quot;deleted_at&quot;`
}

type UserRequest struct {
    Email    string `json:&quot;email&quot;`
    Password string `json:&quot;password&quot;`
}

func CreateUserRepo(newUser UserRequest) (*User, error) {

    user := User{Email: newUser.Email, Password: newUser.Password}
    fmt.Println(user)
    result := services.PostgresSQLDB.Select(&quot;Email&quot;, &quot;Password&quot;).Create(&amp;user)
    fmt.Println(result.RowsAffected)

    if result.Error != nil {
        modules.Logger.Error(result.Error)
        return nil, result.Error
    }

    return &amp;user, nil

}
</code></pre>
<p>You can see i get an empty string for both id and created_at although those values have been auto generated by my database.</p>
<pre><code>{
    &quot;id&quot;: &quot;&quot;,
    &quot;email&quot;: &quot;test@test.com&quot;,
    &quot;password&quot;: &quot;password&quot;,
    &quot;created_at&quot;: &quot;&quot;,
    &quot;updated_at&quot;: &quot;&quot;,
    &quot;deleted_at&quot;: &quot;&quot;
}
</code></pre>
<p><a href=""https://i.stack.imgur.com/oenzg.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/oenzg.png"" alt=""enter image description here"" /></a></p>
<p><strong>testing</strong></p>
<p>To some extend i think this comes down to writing the &quot;proper&quot; types that gorm expects.</p>
<ol>
<li>It seems like Id will return the uuid if i add <code>gorm.Model</code> to my struct, but it also returns back a bunch of fields that seem like duplicates that i dont want (ID, CreatedAt, UpdatedAt, DeletedAt). Removing gorm.Model, Id no longer gives me back the uuid generated by postgres</li>
</ol>
<pre><code>    type User struct {
        gorm.Model
        Id        uuid.UUID      `json:&quot;id&quot;`
        Email     string         `json:&quot;email&quot;`
        Password  string         `json:&quot;password&quot;`
        CreatedAt time.Time      `json:&quot;created_at&quot;`
        UpdatedAt time.Time      `json:&quot;updated_at&quot;`
        DeletedAt gorm.DeletedAt `json:&quot;deleted_at&quot;`
    }
</code></pre>
<pre><code>{
    &quot;ID&quot;: 0,
    &quot;CreatedAt&quot;: &quot;0001-01-01T00:00:00Z&quot;,
    &quot;UpdatedAt&quot;: &quot;0001-01-01T00:00:00Z&quot;,
    &quot;DeletedAt&quot;: null,
    &quot;id&quot;: &quot;b4dea226-3be2-4ee7-8548-67ccbbbcbcca&quot;,
    &quot;email&quot;: &quot;test@test.com&quot;,
    &quot;password&quot;: &quot;password&quot;,
    &quot;created_at&quot;: &quot;2022-06-25T20:59:27.872198797+01:00&quot;,
    &quot;updated_at&quot;: &quot;2022-06-25T20:59:27.872198797+01:00&quot;,
    &quot;deleted_at&quot;: null
}
</code></pre>
<p><a href=""https://i.stack.imgur.com/qkN2d.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/qkN2d.png"" alt=""enter image description here"" /></a></p>
<p><strong>database postgres</strong></p>
<pre><code>-- CreateTable
CREATE TABLE &quot;users&quot; (
    &quot;id&quot; UUID NOT NULL DEFAULT gen_random_uuid(),
    &quot;email&quot; TEXT NOT NULL,
    &quot;password&quot; TEXT,
    &quot;created_at&quot; TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    &quot;updated_at&quot; TIMESTAMP(3) NOT NULL,
    &quot;deleted_at&quot; TIMESTAMP(3),

    CONSTRAINT &quot;users_pkey&quot; PRIMARY KEY (&quot;id&quot;)
);
</code></pre>
",https://stackoverflow.com/questions/72756319/how-to-return-a-newly-created-record-back-from-the-database-using-gorm,"['go', 'go-gorm']",2541,True,2,2
how to speed up TPC-H benchmark on Oracle database,"<p>im trying TPC-H benchmark on my Oracle database, testing takes place on a 10GB dataset. Currently I have target_memory set to 7GB, but the current test time is 18 minutes. The biggest problem is with the lineitem table(7,5GB), because its size does not fit in the cache and with each new query, all data must be reloaded from disk. Do you have any ideas how to speed up the test?</p>
<p>I've already tried the parallelization offered by the optimizer, but it ran even slower with that test due to the HDD and index doesnt work here, because for example in Q1 Oracle need to proccess almost 97% of table lineitem, which is the largest table with a size of 7.5 GB.</p>
",https://stackoverflow.com/questions/71706969/how-to-speed-up-tpc-h-benchmark-on-oracle-database,"['sql', 'oracle', 'benchmarking', 'tpc']",128,False,0,0
How to unit test a Kafka listener that doesn&#39;t change any internal variables,"<p>I've written a Kafka listener in Spring, takes in a message, does some transforming, saves it to a database. Hardly novel stuff.</p>
<p>I'm looking to test the functionality of the message hitting the kafka topic and being ingested by my application (basically just testing if my topic configured right, right group etc).</p>
<p>I have initially achieved this by including an arbitrary payload variable into the class, setting this variable, and checking it's value when I send the right data to embedded kafka. This has worked fine. However, it feels like bad engineering to me to have this variable exist solely for my testing purposes. Is there a way of testing this small bit, the ingest, without this arbitrary variable? I'll be doing separate database testing in the future too.</p>
",https://stackoverflow.com/questions/71127877/how-to-unit-test-a-kafka-listener-that-doesnt-change-any-internal-variables,"['testing', 'apache-kafka', 'spring-kafka', 'spring-test']",332,False,0,0
Can hibernate wait for a record to be present in database before executing?,"<p>I have recently started using hibernate for database testing and come across a scenario where after an API <code>POST</code> request, it can take circa 15 - 25 mins for records to be created in the database. My script sends the request using ReasAssred, it then immediately connects to the database using hibernate to run a query which searches the records generated from the request.</p>
<p>With the help of Java's <code>TimeUnit.MINUTES.sleep(25)</code>, hibernate waits for the record to be present in the table before sending a query, however, sometimes the record can be generated in about 15 mins. Of course, hibernate won't proceed until the 25 mins lapse.</p>
<p>I'm curious. Does hibernate have a smart or fluent way of checking the table at intervals and then execute the query once the data is available, instead of waiting the whole 25 mins? Is there a better way to handle the scenario rather than a dumb 25 mins sleep? I have done ample research online without any concrete resolution, hence this question.</p>
",https://stackoverflow.com/questions/72116791/can-hibernate-wait-for-a-record-to-be-present-in-database-before-executing,"['java', 'hibernate', 'jpa']",218,False,1,0
Laravell PHPUnit database test consume 16Gb ram and crashes,"<p>I tried to make a unit test that makes a database query, but any time I run <code>php artisan test</code>, PHP starts consuming memory until there is no free RAM on my virtual server.</p>
<p>For testing I have increase the virtual server RAM up to 16 Gb and it consumes all 16 GB and then crashes!</p>
<p>So I got simple test from a Laravel tutorial project and tried creating a unit test on it.</p>
<p>Here is the Model:</p>
<pre class=""lang-php prettyprint-override""><code>namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Carbon\Traits\Timestamp;
use Laravel\Sanctum\HasApiTokens;

class Student extends Model
{
    use HasFactory, HasApiTokens;

    protected $table = &quot;students&quot;;

    protected $fillable = [
        &quot;name&quot;,
        &quot;email&quot;,
        &quot;password&quot;,
        &quot;phone_no&quot;,
    ];

    public $timestamps = false;
}
</code></pre>
<p>And a Unit Test:</p>
<pre class=""lang-php prettyprint-override""><code>namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use App\Models\Student;

class ExampleTest extends TestCase
{
    public function setup() : void
    {
        $this-&gt;setup();
    }

    /**
     * A basic test example.
     *
     * @return void
     */
    public function test_example()
    {
        $st = new Student();

        $st-&gt;select(&quot;*&quot;)-&gt;get();
        $this-&gt;assertTrue(true);
    }
}
</code></pre>
<p>And the testing result:</p>
<pre class=""lang-php prettyprint-override""><code>
   Symfony\Component\Process\Exception\ProcessSignaledException 

  The process has been signaled with signal &quot;9&quot;.

  at vendor/symfony/process/Process.php:441
    437▕             usleep(1000);
    438▕         }
    439▕ 
    440▕         if ($this-&gt;processInformation['signaled'] &amp;&amp; $this-&gt;processInformation['termsig'] !== $this-&gt;latestSignal) {
  ➜ 441▕             throw new ProcessSignaledException($this);
    442▕         }
    443▕ 
    444▕         return $this-&gt;exitcode;
    445▕     }

      +15 vendor frames 
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
</code></pre>
<p>I tried many thing, change settings and etc, but nothing helped!</p>
<p><strong>Update 1</strong></p>
<p>Just for information:</p>
<pre><code>php -v
PHP 8.1.10 (cli) (built: Sep 18 2022 12:52:19) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
</code></pre>
<p><strong>Update 2</strong>
I create simple minimal project:</p>
<p><a href=""https://github.com/vasiliyaltunin/LaravelPhpUnitDatabase"" rel=""nofollow noreferrer"">https://github.com/vasiliyaltunin/LaravelPhpUnitDatabase</a></p>
<p>So you can test it yourself, maybe there PHP version problem or other things i try everything already!</p>
<p><strong>Update 3</strong></p>
<p>Thansk to all problem resolved!</p>
<p>I hope test project help ppls to understand how database testing works.</p>
<p>I updated test project by adding seeder for table and use RefreshDatabase, so on every tests run it will be wipe and reseed tables!</p>
<p>You can remove use RefreshDatabase; if you dont want to loose you data every time!</p>
",https://stackoverflow.com/questions/73850581/laravell-phpunit-database-test-consume-16gb-ram-and-crashes,"['php', 'laravel', 'phpunit', 'laravel-8']",56,True,0,1
Should something this be a unit test or something else? Using Laravel 8,"<p>I've recently built an app that imports around 4500 rows from Excel into a MongoDB database. I have the import working really well, but now I'm running into the GIGO issue.</p>
<p>The excel spreadsheet has a column called 'program_url', this column is supposed to be an external link. About a thousand of these are malformed or lead to 404s.
I've managed to fix the malformed urls during the import (http:www. typt things), but there are quite a few that just lead to a 404 page, and I wanted to test that.</p>
<p>My question is, is it better to test for an HTTP 200 status while I'm running the import? Or should it be part of a unit/feature/browser test? If the latter.. how would I go about doing that?</p>
<p>In the Dusk test I have the following code as a test..</p>
<pre><code>    public function test_program_urls()
    {
        $programs = Program::all()-&gt;take(5);

        foreach($programs AS $program) {

            $this-&gt;browse(function (Browser $browser) use ($program) {
                $browser-&gt;visit($program-&gt;program_slug)
                    -&gt;clickLink($program-&gt;program_name)
                    -&gt;assertSeeLink($program-&gt;program_name);
                 

            });


        }

    }
</code></pre>
<p>The test/assertions pass, but I don't see a way to check the status of ClickLink (<a href=""https://laravel.com/docs/8.x/dusk#available-assertions"" rel=""nofollow noreferrer"">https://laravel.com/docs/8.x/dusk#available-assertions</a>)</p>
<p>I tried to do this as a Database test, but that has even fewer assertions..https://laravel.com/docs/8.x/database-testing#available-assertions</p>
<p>Perhaps I'm answering my own question.. and I should just test during the seeding/import and either fix the Excel sheet everytime I run into an issue, or log all the 404s, for future inspection.</p>
",https://stackoverflow.com/questions/70719169/should-something-this-be-a-unit-test-or-something-else-using-laravel-8,"['php', 'laravel', 'phpunit']",80,True,1,1
