How can I setup my environment to use h2 for tests and mysql for development? - database

I'm using the default configuration for the yo jhipster generator except that I'm using mysql as my "dev" database. When I run mvn test my tests succeed with no failures.
However, I found that if I ran tests a second time, the suite would fail since it would run against the "dev" database...that wasn't 'rolled back' or 'reset' after the previous test run. I would rather have expected it to run against an in-memory h2 database as configured in src/test/resources/config/application.yml that would be reset after each run.
How can I setup my environment with h2 for tests and mysql for development?
Thanks

I'm not sure if this is the "right" way to solve this but I was able to get my tests to pass on repeated runs by creating a new profile "test".
I then had to do 2 things:
1) change spring.profile in src/test/resources/config/application.yml to "test" instead of "dev" (to make the test application.yml different from the dev one)
2) use #ActiveProfiles("test") instead of #ActiveProfiles("dev") in my tests
The test application.yml uses an h2 database and is reset between runs as desired.
Note: I also had some success with successive test runs without creating a new profile by annotating my test classes with:
#Transactional
#TransactionConfiguration(defaultRollback = true)
as...
At the end of the test the transaction will be rolled back and the data discarded leaving a fresh environment for the next test to execute.
see https://spring.io/guides/tutorials/data/3/

Related

How to glue together Vert.x web and Kotlin react using Gradle in Kotlin MPP

Problem
It is not clear to me how to configure the Kotlin MPP (multiplatform platform project) using Gradle (Kotlin DSL) to use Vert.x web for Kotlin/JVM target with Kotlin React on the Kotlin/JS target.
Update
You can check out updated minimal example for a working solution
inspired by an approach of Alexey Soshin.
What I've tried
Have a look at my minimal example on GitHub of a Kotlin MPP with the Vert.x web server on the JVM target and Kotlin React on the JS target.
You can make it work if you:
First run Gradle task browserDevelopentRun (I don't understand magick behind it) and after browser opens and renders React SPA (single page application) you can
stop that task and then
start the Vert.x backend with task run.
After that, without refreshing the remaining SPA in the browser, you can confirm that it can communicate with the backend by pressing the button and it will alert received data.
Question
What are the possible ways/approaches to glue these two targets so when I run my application: JS target is assembled and served via JVM backend conveniently?
I am thinking that perhaps Gradle should trigger some of the Kotlin browser tasks and then make them available in some way for the Vert.x backend.
If you'd like to run a single task, though, you need that your server task would depend on your JS compile. In your build.gradle add the following:
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(tasks.getByName<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("jsBrowserProductionWebpack"))
}
Now invoking run will also invoke WebPack.
Next you want to serve your files. There are different ways of doing it. One is to copy them to Vert.x resources directory using Gradle. Another is to point Vert.x to where WebPack puts them by default:
route().handler(StaticHandler.create("../../../distributions"))
There is a bunch of different things going on there.
First, both your Vert.x and Webpack run on the same port. Easiest way to fix that is to start Vert.x on some other port, like 18080:
.listen(18080, "localhost") { result ->
And then change your index.kt file to use that port:
val result: SomeData = get("http://localhost:18080/data")
Because we run on different ports now, we also need to specify CORS handler:
router.apply {
route().handler(CorsHandler.create("*"))
Last is the fact, that you cannot run two neverending Gradle tasks from the same process (ok, you can, but that's complicated). So what I suggest is that you open two Terminals, and run:
./gradlew run
In one, and
./gradlew jsBrowserDevelopmentRun
In another.
Having done all that, you should see this:
Now, this is for development mode. For production mode, you probably don't want to run jsBrowserDevelopmentRun, but tie jsBrowserProductionWebpack to your run and server spa.js from your Vert.x app using StaticHandler. But this answer is already too long.

rails 5 run script only after server start

I want to run a ftp listener class only when the server starts and not when console, generators, dbconsole, test, destroy, runner and rake commands run.
I've found some people doing same thing with rails 3 and 4 using checks like defined? Rails::Generators but I can't get it working in rails 5, I do not get any return with the defined check.
The config.ru file is only used by web servers and not loaded by the console script, rake tasks or even your test suite. What you put there is only executed when a server instance launches.
Web servers themselves have also ways to do this. When you use Puma for instance, there are hooks like on_worker_boot or after_worker_boot, which may come to help (http://www.rubydoc.info/github/puma/puma/Puma/Configuration/DSL).
However, I'd recommend integrating this into your deployed server environment and out of the Rails app.

How to setup endless testing with Protractor with SauceLabs?

I have a webserver with protractor tests on it, i want to setup endless testing with saucelabs.
They say just add sauceLabs user and key to the conf.js file of protractor.
Should I use cron or something else to make it endless testing loop ?
This is something you should not solve on the protractor level.
Use jenkins or other continuous integration servers, or simply schedule it in cron.

Coded UI Test with Teamcity

I run MSTest to test WPF application (Coded UI Test) on a VM using Teamcity. I already installed test agent as interactive process but i keep getting this error in Teamcity log
Error calling Initialization method for test class Squarebit.Apms.Terminal.Wpf.Test.CodedUITest1: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: To run tests that interact with the desktop, you must set up the test agent to run as an interactive process. For more information, see "How to: Set Up Your Test Agent to Run Tests That Interact with the Desktop" (http://go.microsoft.com/fwlink/?LinkId=255012)
If you are running the tests as part of your team build, you must also set up the build agent to run as an interactive process. For more information, see "How to: Configure and Run Scheduled Tests After Building Your Application" (http://go.microsoft.com/fwlink/?LinkId=254735)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.Initialize()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestExtensionExecution.BeforeTestInitialize(Object sender, BeforeTestInitializeEventArgs e)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecution.RaiseBeforeTestInitialize(BeforeTestInitializeEventArgs args)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.RunInitializeMethod()
Can you help me resolve this problem or recommend some ways to run Coded UI Test using Teamcity?
Coded UI tests (CUIT) can't run from a service account since they need access to Desktop Windowing API set.
Please refer Installing the teamcity build agent section in http://jake.ginnivan.net/teamcity-ui-test-agent/ to setup teamcity agent as a non-service account.

Is there a way in phpunit to use the database extension together with the selenium extension?

Basically, I want to run selenium tests that allow the database to be setup to a define status before each Selenium test. How would I do this?
Given that Selenium just calls url's you could simply use the setUp() and tearDown() methods to get your database into a specific state. Transaction rollback is one approach to keeping the database consistent.
Then call url's mapping into the project under test (and your test database) e.g.:
$this->open('http://testing.example.org/system/under/test.php');
I have written my own database setup and teardown routines which I added to a child of selenium testcase

Resources