New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated test (Travis + PHPUnit) #577

Closed
marienfressinaud opened this Issue Aug 12, 2014 · 17 comments

Comments

Projects
None yet
4 participants
@marienfressinaud
Copy link
Member

marienfressinaud commented Aug 12, 2014

I was thinking today it would be awesome to have a strong test suite. I think PHPUnit is a good framework for our tests (at least, the best known). Travis CI could be used as continuous integration platform to test automatically commits and PR. The best would be to check test coverage!

I know it's a lot of works but it can help to not lose too much time to find bugs and regressions. And it's a really good for communication :D

@marienfressinaud marienfressinaud added this to the 1.0.0 milestone Aug 12, 2014

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Aug 12, 2014

I agree. There is also atoum which make a good job.

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Sep 5, 2014

We should have also test for Javascript, perhaps with QUnit
And also tests for UI, perhaps with Selenium

More here

@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Oct 5, 2014

I will try Atoum + Travis CI today on lib_ompl library (https://github.com/marienfressinaud/lib_opml) :)

@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Oct 5, 2014

@aledeg > Do you know how I can test a simple function with atoum? All the examples take classes as basis and I couldn't find any examples on Internet for testing functions… If you have some sample files it could be great :)

@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Oct 5, 2014

If atoum is similar to phpunit, it will be hard to write tests for functions...

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Oct 5, 2014

Actually, I think it is the same as testing within a class. The problem is when you try to run the tests from the tested file in Netbeans because it cannot find a class to test.
But I think if you take the example in the first link and you change it this way

function odd_or_even( $num ) {
    return $num%2; // Returns 0 for odd and 1 for even
}

class test extends PHPUnit_Framework_TestCase {
    public function testodd_or_even_to_true() {
        $this->assetTrue( odd_or_even( 4 ) == true );
    }
}

I think it will work properly.

Before starting on tests, maybe it could be a good idea to determine conventions. At work, I like to use the following convention while naming test cases.

// Model
public function testMyFunctionName_whenIDoSomething_whatIExpect() {
}

// Example
public function testlibopml_parse_file_whenTheFileDoesNotExist_raiseException() {
     // do something here
}
@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Oct 5, 2014

I don't use Netbeans: the problem is PHPUnit and atoum expect to test classes and not functions.

I succeed to write my first test with PHPUnit but it didn't work with atoum because when I wrote:

class HelloWorld extends atoum {

}

atoum was searching for another class called HelloWorld in my source code (in a different namespace of course). Problem was I hadn't class in my source code!

Anyway, I succeed with PHPUnit : https://github.com/marienfressinaud/lib_opml/blob/master/tests/renderTest.php

I will follow your convention but I prefer to add an underscore after "test"

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Oct 5, 2014

The workaround is to create a static class with static method. But in our case, maybe it is not worth it.

@marienfressinaud marienfressinaud modified the milestones: 2.0.0, 1.0.0 Dec 9, 2014

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Jan 17, 2015

I am trying to test the class FreshRSS_Share and I wonder the reason for a private constructor and static methods. It makes testing hard and I am not sure if we can not split the class in 2.

I think the static methods are related to a Shares class which will own a Share collection. Any thoughts?

@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Jan 17, 2015

Yes probably but I would like to avoid this kind of changes before the release of the 1.0.

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Jan 17, 2015

I am now trying to test the Category class but it is highly coupled. My guess is that most of the code of FreshRSS is build the same way. If we want to be able to test properly, I think we need to refactor again the code by introducing more dependency injection and making the functions into classes.
I don't say we need to do everything in one big refactoring but I think it will be a good thing if we want to make it testable.

@marienfressinaud

This comment has been minimized.

Copy link
Member

marienfressinaud commented Mar 6, 2015

I would like to try to set up travis-ci with FRSS. We'll need a .travis.yml file but I can already try to enable the Travis switch button to see what happens :).

@aledeg

This comment has been minimized.

Copy link
Contributor

aledeg commented Mar 14, 2015

I think in the future, with a nice test suite, we should consider using humbug for mutation testing.

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented May 27, 2017

Copying this from my inadvertent duplicate:

It looks like FreshRSS isn't making the most of GitHub integration yet. Here are some hopefully helpful suggestions to get started.

Of course I'm willing to help think about and implement these.

@Alkarex

This comment has been minimized.

Copy link
Member

Alkarex commented May 27, 2017

@Frenzie Help very much welcome :-)

@Alkarex Alkarex modified the milestones: 2.0.0, 1.7.1 Sep 22, 2017

@Alkarex

This comment has been minimized.

Copy link
Member

Alkarex commented Sep 22, 2017

Travis added by @Frenzie #1619

@Alkarex Alkarex closed this Sep 22, 2017

@Frenzie

This comment has been minimized.

Copy link
Member

Frenzie commented Sep 22, 2017

It'll still need to be extended from mere linting to actual unit tests of course. But yes, with some basic setup out of the way it'll be much easier to keep adding things incrementally. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment