[SalesForce] How to create a correct test for knowledge articles

I'm creating a package with a simple Apex class that retrieves info about knowledge article (Lighting Knowledge).
However, I'm having an issue with a test. When installing the package via installation link on another org, it fails with the following error:

The name "Knowledge__kav" is already used on component type: Article
Type. Please rename existing component.

My understanding was that Knowledge__kav is a default record type for knowledge articles. In the other case, what is the correct way to implement the test?

public with sharing class ContentController {
    @AuraEnabled(cacheable=true)
    public static KnowledgeArticleVersion getArticleById(Id id) {
    return [
      SELECT Title, ArticleCreatedDate
      FROM KnowledgeArticleVersion
      WHERE Id = :id
      AND PublishStatus = 'Online'     
    ];
  }
}
@IsTest
private class ContentControllerTest {
  @IsTest static void validateGetArticleById() {
    String articleTitle = 'Test Article';
    String articleBody = 'Test Body';
    String articleUrlName = 'test';
    String language = 'en_US';

    Knowledge__kav article = new Knowledge__kav(
      Title = articleTitle,
      Summary = articleBody,
      UrlName = articleUrlName,
      Language = language
    );

    insert article;

    Knowledge__kav currentArticleDetail = [
      SELECT ArticleCreatedDate, ArticleNumber
      FROM Knowledge__kav
      WHERE Id = :article.Id
    ];

    KnowledgeArticle knowledgeArticle = [
      SELECT Id
      FROM KnowledgeArticle
      WHERE ArticleNumber = :currentArticleDetail.get('ArticleNumber').toString()
    ];

    KbManagement.PublishingService.publishArticle(knowledgeArticle.Id, true);

    sObject articleDetail = ContentController.getArticleById(article.Id);
    System.assertEquals(articleTitle, articleDetail.get('Title'));
  }
}

Best Answer

So it's possible to create an new instance dynamically:

Type kType = Type.forName('Knowledge__kav');
if (kType != null) {
  Object ko = kType.newInstance();
  if (ko instanceof SObject) {
    SObject kso = (SObject)ko;
    kso.put('Title', 'Test Article');
    kso.put('UrlName', 'test-article');
    insert kso;
  }
}