Seperate Test Suites & Seeders in Laravel/PhpUnit - laravel

Is it possible to run a set collection of test suites & seeders within Laravel? For example, i have one codebase for a project which is home to different clients. Each of these clients have different requirements, so the tests are going to differ, along with the seeder.
How can I package these tests so that I can can run one set without running them all? I understand we can create test suites within phpunit, but all my seeders will run which will create excess load on a server when I only want to test a specific set.
Thanks.
I've created seperate 'main' file seeders.
ClientASeeder (Calls more seeders)
ClientBSeeder (Calls more seeders)
...
And seperate test folders, for each client. Along with a generic test folder for shared tests.

Related

Is there a way to run molecule tests with external dependencies?

I have several roles that run actions on a remote database that executes sentences for user and privilege creation.
I have seen molecule used to test playbooks that run against a single host, but I am unsure of how you could setup a second container to run a docker instance in the same network as the molecule container (similar to a docker-compose setup). However I have not been able to find a setup like this in the documentation.
Is there a recommended way to run molecule tests with external dependencies? Or should I just use docker-compose or similar to run my tests?
There is a 'prepare' stage in Molecule specifically for that. You need to separate questions:
where external resource (database) is run?
why and how it's configured?
Those are very separate, and mixing them together is a bad idea.
For 1 there are different answers:
It is (out of blue, configured by other people). Use non-managed hosts in molecule.yml.
We OK to run it on the same host as the host we run our code. Shovel installation into 'prepare' stage.
We want it to be on separate server. Put additional host in platforms in a different group and configure it in prepare stage.
If you find your driver is not good enough, you always can opt for 'delegated' driver. In this case you need to write playbooks for create/destroy of hosts. It's relatively easy. The main trick is to use 'platforms' variable to get information about content of molecule.yaml's platform section.

Load a resource into a frame work from an app

I have a framework I wrote for an app and now I am writing some unit tests for it. To complete the test suite, I need to load a configuration file from the main app into my framework's unit tests. When I try to use Bundle(for: self.classForCoder) and load that config file, it returns nil all the time. Any thoughts?
Neither your framework, nor the tests for it, can access your main app bundle that way.
Since your app provides the config file to the framework, your tests can do the same. If you can use a test config file, just add it to your test bundle. If you need a copy of the actual config file, then make a copy.
(You may want a Run Script build phase to do the copying. Don't forget that just making a copy isn't enough — you still need to add it to the test target.)

Parallel Testing Rspec

I am trying to run my Rspec tests in Parallel but doing so causes data conflicts i.e I have a delete_all method to give me a clean slate every tests run which causes tests running in parallel to lose the data they have created. What would be the ideal way to resolve this?
Separate Databases.
Not sure how you are running your tests in parallel. Parallel tests should each have their own databases, otherwise, yes, you'll get massive data conflicts.
If your parallel test runners are sharing the same database and you call delete_all on one of your runners, it will cause the other runners to fail because their test databases (which are all the same) will now be empty.
Gems like parallel_tests use separate databases for each test runner by suffixing the test database name with the runner number, e.g. test_database1, test_database2, etc.
So, you should use one of these pre-built libraries that helps take care of this but if you're rolling your own, then make sure you run each runner in a separate database to avoid database conflicts.

Flyway migration in Development and Production

I searching for an way to do a different migration in production and development.
I want to create a Spring Webapplication with Maven.
In development i want to update database schema AND load test data.
In production when a new version of the application is deployed i want only change the schema and don't load test data.
My first idea was to save the schema update and insert statements into different folders.
I think every body has solved this problem and can help me, thank you very much.
Basically, you have two options:
You could use different locations for your migrations in your flyway.locations property, i.e.:
for Test
flyway.locations=sql/structure,sql/test
for Production
flyway.locations=sql/structure
That way, you include your test data in the sql/test folder. You would have to take care with numbering, of course.
The second option (the one I prefer), is don't include test data in your migrations at all.
Rather, create your testdata any way you want and create an sql-dump of this data, which you keep separate from your migrations.
This works best if you have a separate database (instance, schema, whatever) containing your pristine testdata, where you apply each migration as part of your build process. This build job could then create a dump always matching the current migration.
When preparing your test machine, you first apply your migrations, then you load the contents of the matching dump.
I think this is a lot cleaner than the first version, especially because your test data can be prepared using other tools (your application) and has not to be handcoded.

Per-test sample data generation for load testing?

I have a set of load tests, each testing a specific section of Sharepoint site. How can I automate the generation of sample data prior to each test?
I know that load tests allow me to specify tests that are run before/after a specific virtual user's test mix, but those are meant for user-specific setup like logging on. I want to create sample data for all users.
I can put my setup code into the Team Build template, but that doesn't take into account whether the test using the sample data is in the test list being run or not. If I modify the test list, I would also need to modify the build template as well. I cannot put the setup code into a test that is run before the load test either, because load tests must be run with the .Net 4.0 framework while accessing Sharepoint's API requires 3.5.
I could rewrite my sample data generation logic with Powershell and start it from a .Net 4.0 unit test. Is it my best option or is there a more elegant way?
I think you question is more TeamBuild related than SharePoint. For short, the best way how to setup (and teardown) testdata in SharePoint is using PoSh in conjunction with the Microsoft.PowerShell.SharePoint SnapIn.
You can start your PowerShell scripts from Everywhere in TeamBuild. That's actually how I extend the default TeamBuild template. I've create a single custom build template, this template contains numerous PoSh hooks. While setting up a new project you can easily hook your scripts everywhere you need.
To be really independent from any .NET FX version you could create your sampledata using REST DataServices (ListData.svc)

Resources