How to unit test django application using jena-fuseki? - django

My django application uses sparql with jena-fuseki RDF-database. How should I run my unit tests as thete's hardly any information in availble for creatig in-memory jena database for a django unittesting ? So far I've been just running a local fuseki-server, but that's not the way unit testing should be done, right ?

Related

How to unit test ML.NET prediction?

I have a ML.NET project deployed as a web api like this - https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/serve-model-web-api-ml-net
How do I mock the PredictionEnginePool, MLContext or the PredictionEngine in xUnit or any unit test framework?
Have you looked at the tests for ML.NET? MLContext is shown in those examples.
https://github.com/dotnet/machinelearning/tree/master/test
PredictionEnginePool (I don't believe is shown), but it is not a special construct that can't be tested. I would test the FileLoader and being able to test from remote locations if you have to.

In Django 1.6 - how to use a pre-existing database for unit tests? (--keepdb flag)

We are using Django 1.6.x for our codebase and there are no unit tests for the code.
I want to begin to implement unit tests on the codebase and we have a Oracle database we can use for the task. On other codebases we maintain, I can use the --keepdb flag to prevent django from creating/tearing down the database.
Apparently in earlier versions of Django this flag doesn't exist.
Created a custom settings file but I cannot figure out how to prevent the modification of db tables I do not have permissions for.

How to write unit test for Ebean in play framework

I have an application based on play framework scala version 2.11.1.
There are couple of methods for which I want to add unit tests. These methods have direct calls to database through Ebean.
I tried with this link to use mocki-ebean in order to mock these calls. But the import was unsuccessful
I tried with powermock as well. but it requires to setup in-memory ebean server for mock calls. But that is also deprecated to setup in-memory server for unit testing.
Any idea what could be the next direction?

Testing Angular and Django Rest Framework apps

Let's say I have a frontend application written in Angular and a backend application written in Django and Django Rest Framework. I created unit tests for backend application (with pytest) and I'm about to create some functional tests for the frontend application. The thing is that the frontend app needs access to the backend app in order to work correctly. I can write some mocks to handle that, but I am not sure if this is the best way to do that.
My question is, what is the best way to handle that? Should I use a single git repo for both applications or maybe a better way is to use two repositories, but then how to handle the tests for frontend application?
I was also thinking about using selenium with pytest, but then I would have to use a single repository. I am a little bit confused and would really use some good advice. Thanks!
Unit tests as the name suggests is testing separate units of the code in isolation. Meaning that it does not have to depend on any other part, else, you wouldn't know if the test is failing for that particular unit or the units it depends on.
As a result, all tests should mock the request to the backend and return valid responses (or invalid, if you're testing for error handling). The same applies to any other external service that the unit depends on.

Selenium and Django: how to mock the server?

I'm starting to introduce Selenium tests to my website that is written in Django. The browser that is controlled by Selenium needs some server to connect. So far I just run my full application in a separate process, but this is painful.
I'd like to run some mock HTTP server, make it serve all the necessary static files and render Django templates and return mock responses to some specific requests.
How would you do that?
Can you not run Selenium over django dev server http://localhost:8000/ .
If not perhaps worth looking at http://harry.pythonanywhere.com/ .where there are some good resources
The best thing is to integrate selenium tests into your unit test suite. When Django 1.4 comes out this will be a supported feature, where the Django test runner will run a development HTTP server for you while the tests run, and load all of your test fixtures for you:
support-for-in-browser-testing-frameworks
LiveServerTestCase
Likely you can't wait until the 1.4 release. In the meantime, you can use something called django-nose-selenium to do this:
https://github.com/weluse/django-nose-selenium
There's a good comprehensive guide on how to do this here:
http://timescapers.com/2011/08/27/django-nose-selenium-a-concise-tutorial/
If I may plug-plug my own tutorial, which will allow you to do full selenium testing against the django test server
http://www.tdd-django-tutorial.com/