Dariusz on Software Quality & Performance

07/01/2014

QUnit – Unit Testing made easy for JavaScript

Filed under: en — Tags: , — dariusz.cieslak @

Are you test-infected?  Learned already how to grow your server-side apps using unit testing and want to do the same with client (HTML) layer? Search no more! QUnit to the rescue!

289

QUnit is a JavaScript library that helps you with tests specification, run and diagnostics. Firstly, you have to include qunit library and your tests in an html file:

<html>
<head>
<link rel="stylesheet" href="/resources/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="/resources/qunit.js"></script>
<script src="/resources/tests.js"></script>
</body>
</html>

Then you can start writing your tests, the simplest one, taken from documentation:

(more…)

22/12/2013

Classic Testing vs Design By Contract

Filed under: en — Tags: , , — dariusz.cieslak @

Automated unit tests are hard to write. Software architecture must be designed carefully to allow unit testing. You have to spend time to write tests as well and it's not easy to write good tests. It's easy to make big mess that is hard to maintain after few weeks.

On the other hand automated integration tests are hard to maintain and are fragile. You can "write" them pretty easy in a record-and-replay tool, but later they show their real cost during maintenance.

But there's an answer for problems mentioned above. Do you know Eiffel language? The language has special built-in constructs that support executable contract specification. It's called Design By Contract (DBC). DBC is easier to write and to maintain because no special test cases need to be specified, just conditions for method parameters, expected results and state invariant that must be preserved. How DBC can substitute old-fashioned tests? Read on!

(more…)

02/12/2013

JPA + ObjectDB example

Filed under: en — Tags: , , — dariusz.cieslak @

JPA stands for "Java Persistence API" – an API that tries to replace direct Hibernate (or other ORM) usage with more generic layer that allows to replace underlying ORM with no application code changes.

Although ORM (object relational mappers) typically use relational database under the hood JPA is not restricted to relational databases. I'll present how object database (objectdb) can be used using JPA interface.

All the source code can be located here: https://github.com/dcieslak/jee-samples/tree/master/jpa.

Classes

Firstly, you have to define your model and relations using POJO with JPA annotations. We try to make model as simple as possible, so no getters/setters pairs if not really required.

@Entity
class SystemUser implements Serializable {

    @Id @Column @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer userId;

    @Column
    public String systemUserName;

    @Column
    public Departament department;

    public String toString() {
        return "SystemUser(" + systemUserName + ", " + department + ")";
    }
}

(more…)

29/11/2013

Check current network bandwidth used on a Linux/Unix box

Filed under: en — Tags: , — dariusz.cieslak @

Sometimes you need to quickly measure current bandwidth used by your Linux box and don't have dedicated command installed. You can use standard /proc/ file entries to get that info from the system.

Example of a embedded device with a TS stream as an input:

( cat /proc/net/dev; sleep 1; cat /proc/net/dev; ) | awk '/eth0/ { b=$1; sub(/eth0:/,"",b); if(bp){ print (b-bp)/1024/1024, "MB/s" }; bp=b }'
1.00053 MB/s

28/11/2013

The simplest MySQL setup, ever

Filed under: en,pl — Tags: , — dariusz.cieslak @

logo-mysqlFirst of all: you have to install the server (I assume you use Debian / Ubuntu):

apt-get install mysql-server

Then you have to create database, user and password (for sake of simplicity, not security, name, login and password are the same):

N=<DB_NAME>; echo "create database $N; grant usage on *.* to $N@localhost identified by '$N'; grant all privileges on $N.* to $N@localhost ;" | mysql -u root

Then you should configure your program:

  • db_name=<DB_NAME>
  • db_user=<DB_NAME>
  • db_password=<DB_NAME>
  • host=localhost

Beware (SECURITY): I assume you have MySQL external connection closed (only local) and you trust every user from your Linux installation, they will have access to your database easily in such setup.

« Newer PostsOlder Posts »

Powered by WordPress