insert data to database before running protractor e2e test - unit-testing

I have protractor e2e tests in my project, but I have a problem to insert data to the db before running the e2e test. What is the way to do it? I have java unit test that can insert the data. Is there a way to call the java unit tests from protractor?
Thanks,

You can define a function in your protractor configuration file:
// protractor.conf.js
exports.config = {
beforeLaunch: function() {
// You can do it here.
}
...
onPrepare: function() {
// Or here.
}
https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L178
You can run a java process from node with child_process. Call java from the onPrepare function: http://nodejs.org/api/child_process.html

Related

scalatest run integration test separately from unit test

I am using scalatest maven plugin and I would like to run integration test separately from unit tests. The tests path are src/it and src/test for integration test and unit test respectively.
Which is the best approach to achieve this goal?
Thanks
One option is to create an object and then use it as a tag in each test:
object IntegrationTag extends Tag("Integration-Test")
test("Test for correct number of records", IntegrationTag) {
// some stuff
}
Then, if you want to test the Unit Tests simply run the command:
mvn test -DtagsToExclude=Integration-Test
This is a possible solution...sure that will be more.

How do I perform unit tests involving redis, socket.io, and nodejs/express?

I am currently running into problems attempting to create unit tests that involve the interaction of socket.io, redis, and express. I'm looking for strategies on how to best mock these interactions. For example, I am using socket.io-client to mock the connection/behavior of socket.io to my express server but then when I add a test to check if redis is storing the proper information from socket.io I find myself needing to also mock socket.io in the redis unit test which in turn means I need to mock the express server. This leads to the point where it seems like I'm rewriting another server just to unit test the actual server I am trying to test.
Has anyone had to do this before? If so could you point me to resources (google/stack overflow are slim in results)?
What part of the application are you trying to test?
One way is encapsulating the socket connection in a socket.service.js file.
const socketIO = require('socket.io');
class SocketService {
constructor(server) {
this.socket = socketIO(server);
}
initialize() {
this.socket.on('connection', socket => {
console.log('connected')
socket.on('disconnect', () => {
console.log('disconnected')
});
socket.on('register', registerHandler);
socket.on('update', updateHandler);
});
}
}
Your unit test could be that it registers agains a mock server, and that it calls the initialize method.
If you are trying to test all of them working together, then you are talking about integration and e2e testing.

Zend Framework 2 unit testing using CodeCeption

We are currently using CodeCeption to do some acceptance testing, but I would like to also add unit testing to the current setup.
Has anyone done Unit testing in Zend Framework 2 project using CodeCeption? And if so, how did you set up the environment?
Found this in codeception docs: http://codeception.com/docs/modules/ZF2
There is an example in this github project: https://github.com/Danielss89/zf2-codeception
I solved this problem by using PHPUnit. I followed the Zend PHPUnit guide, http://framework.zend.com/manual/current/en/tutorials/unittesting.html, which only got me so far. But, I was able to bootstrap Zend using a phpunit.xml file and pointing that to _bootstrap.php. Codeception is also able to bootstrap my tests using the _bootstrap.php file. So, now I can run my tests using both:
phpunit --bootstrap tests/unit/_bootstrap.php
and
php vendor/bin/codecept run unit
I was surprised to see how few examples there are for this. I was writing tests for a job queue client. Here is a bit of my test:
protected function setUp()
{
$this->serviceManager = new ServiceManager(new ServiceManagerConfig());
$config = Bootstrap::getConfig();
$this->serviceManager->setService('ApplicationConfig', $config);
$this->serviceManager->get('ModuleManager')->loadModules();
$this->client = $this->serviceManager->get('jobclient');
$this->client->addServers(array(array('ip' => '127.0.0.1', 'port' => '666')));
}
public function testServiceCreateSuccess() {
$this->client->setQueue($this->testData['queue']);
$this->assertEquals($this->client->getQueue(), $this->testData['queue'], 'We get the expected queue');
}
I mocked the job client and had a local config. My _bootstrap.php file looks basically the same as the Zend example except that I am using factories defined in the service config to manage some objects. So, I performed the "setService" method in the test setup rather then in the bootsrap init.

Using IOC To Configure Unit and Integration Tests

I have a unit test project which uses Ninject to mock the database repositories. I would like to use these same tests as integration tests and use Ninject to bind my real database repositories back into their respective implementations so as to test/stress the application into the DB.
Is there a way to do this with Visual Studio 2012 or is there another test framework, other than MSTest, which allows for this type of configuration?
I would really hate to rewrite/copy these unit tests into an integration test project but I suspect I could copy the files in as links and have a single test file compiled into two projects (Unit and Integration).
Thanks
Todd
Your requirements sound really odd to me. The difference between a unit test and an integration test is much bigger than just connecting to a database or not. An integration test either has a much bigger scope, or tests if components communicate correctly. When you write a unit test, the scope of such a unit is normally small (one class/component with all dependencies mocked out), which means there is no need for using a DI container.
Let me put it differently. When the tests are exactly the same, why are you interested to do the same test with and without the database. Just leave the database in and just test that. Besides these tests, you can add 'real' unit tests, that have a much smaller scope.
With Nunit you can do this with TestCase,
say you need to use the unit and unit/integration test using CustomerRepository and OrderRepository,
[TestFixture]
public class TestCustomerRepository
{
IKernel _unit;
Ikernel _integration;
[SetUp]
public void Setup()
{
//setup both kernels
}
[TestCase("Unit")]
[TestCase("Integration")]
public void DoTest(String type)
{
var custRepo = GetRepo<ICustomerRepository>(type);
var orderRepo = GetRepo<IOrderRepository>(type);
//do the test here
}
protected T GetRepo<T>(String type)
{
if (type.Equals("Unit"))
{
return _unit.Get<T>();
}
return _integration.Get<T>();
}
}
This is the basic idea.

Anyone have a working Jasmine unittest that runs in Resharper 7 EAP?

I'd really like to be using the R#r test running for my javascript unittests. R#r 7 EAP recognizes the tests but when I launch them the runner shows '... Test wasn't run' for all tests.
I can't find any info on what the R#r test runner expects in terms of configuration/directory structure.
Directory structure and sample test posted here
A basic/hardcoded jasmin unit test does work under R#r 7 EAP. This implies that jasmine is baked in to R#r i guess. Have an open question regarding same.
describe('resharper jasmine testrunner', function () {
describe('simplest possible test', function () {
it('should execute', function() {
expect(true).toBe(true);
});
});
});
Got a pointer on the R#r forum that doc comment references are your 'includes' (or jsTestDriver.conf equiv).
/// <reference path="../../libs/testing/jasmine/jasmine.js"/>
/// <reference path="../../libs/crunch/jquery-1.6.2.js"/>
Have yet to get my real tests passing though the now run. Investigating fixture paths next.
I'm not sure how advanced of a solution/structure you're looking for, as I just started looking into this myself, but i have a simple example test "working"*... (using Resharper 7 EAP 7.0.56.103). As far as i know, you can structure your test files anyway/where you want, as long as you include references to all of its dependencies with <reference path="foo/path/file.js" />)
*These pass inside the ReSharper unit tests session window. The browser does not show me any sort of test info but rather a blank screen with some jasmine-related html in the source.
/scripts/cheese.js
function Cheese() {
return {
isGood: true
};
}
/tests/cheeseTest.js
/// <reference path="/scripts/cheese.js"/>
describe('simplest possible test', function() {
var cheese = null;
it('cheese is good', function() {
cheese = new Cheese();
expect(cheese.isGood).toBe(true);
});
});