How could I test a connection if the datasource is modified?
You can test the connection in the runtime section. The code sample you refer to belongs to the configuration section. In domain mode you need a running server to test a datasource connection. that's the reason why the test connection feature is only available in runtime.